Autonauts

Autonauts

Not enough ratings
Comprehensive Logic Programming with Autonauts
By iggy12345
   
Award
Favorite
Favorited
Unfavorite
What is Boolean Logic?
To avoid a lengthy discussion, boolean logic is the process of formulating ideas into true and false statements. At the most basic of basic levels, just about everything runs on some form of boolean logic, your phone, computer, even this game. I'm here today because I've always wanted to create boolean logic in Autonauts, and I'm going to share my knowledge with you so that you can go out and build computers just like me!

For a much better introduction to boolean logic, that at least includes the history of James Boole, I'd like to direct you to http://wikipedia.
How to use this Guide
This guide will feature some things that may be new to some readers, such as truth tables and other terminology.

Terminology
In this guide I'm going to refer to inputs and outputs often, by these I'm referring to in-game wooden storage crates with or without berries in them. I'm also defining a logical true as being the presence of a berry within a wooden crate, and a logical false as the absence of a berry from a wooden crate. This can be thought of a simplified version of binary, where a berry represents a 1 and no berry represents a 0.

Storage Crate Contents
Logical Value
Empty
False
Berry
True
Multiple Berries
True

Truth Tables
A truth table is a table that describes the operation of a logical gate or operator, it lists all possible combinations of inputs on the left and the corresponding outputs on the right. Fore example, the following table represents a wire, where the output matches the input, in this example 'X' would be an input, and 'Z' would be an output.

X
Z
True
True
False
False
It Starts with an Inverter


What is an inverter? Well, as the name implies, it's output is true, if the input is false. In this case, say that we have 2 berry boxes, one on the left, and one on the right and then we program a bot, such that if the berry box on the left is not empty, then we remove a berry from the box on the right, and if the box on the left is empty, then we place a berry into the box on the right. This is called an inverter, it "inverts" your boolean signal.

The symbols above are the current symbols for an inverter, known as a negation, and a NOT gate. The one on the left is used in predicate and sentential logic, whilst the one on the right is more common in electrical schematics. (Fun fact, in the symbol on the right, it's not actually the triangle that's important, that's actually called a buffer; it's the little circle that represents negation, which you'll see later with NOR and NAND gates).

Below is the truth table for an inverter:

X
Z
True
False
False
True

In Autonauts
So how do we do this in autonauts? Well, this is as simple as telling a bot to place a berry in a crate if another crate is empty, and remove it if it's full, take a look.


And here's the code:

Name
Description
Berry Storage 1
Input 1
Berry Storage 2
Output

Now we need an OR

This is an OR gate, in sentential logic, it's represented with a V, the output of an OR gate is true if either input, or both inputs, are true, take a look:

A
B
Q
false
false
false
true
false
true
false
true
true
true
true
true

And in autonauts:


And the program:

Name
Description
Berry Storage 1
Input 1
Berry Storage 3
Input 2
Berry Storage 2
Output

AND now everything else


With an OR and a NOT under our belts, we can generate all modern computation, though, a bit tedious, it'd definitely possible, for starters, let's make an AND Gate so that we can have a complete AOI logic set.

An AND Gate can be created using an OR and NOT in the following format:

A AND B = NOT ((NOT A) OR (NOT B))

Here's the truth table

A
B
Y
false
false
false
true
false
false
false
true
false
true
true
true

And not in autonauts:


Name
Description
Berry Storage 1
Input 1
Berry Storage 3
Input 2
Berry Storage 2
Output

The Conjunctive Normal Form
Now that we have an AND, OR, and Invert, we can create what are called, conjunctive normal forms (cnf), see http://wikipedia. This basically means that any possible logical circuit can be reduced down to a series of inputs AND'd together and OR'd with more sets of ANDs, it's highly inefficient, but it basically means that we can represent any logical circuit that exists with modern hardware. So let's do some cool stuff with it.
Let's do Basic Arithmetic
XOR
To do some basic arithmetic, we need to create one additional gate, for simplicities sake. For my simplicity's sake, I'm also going to skip over a lot of the explanation here, and simply link to http://wikipedia. Basically, when both inputs are the same, the output is false, otherwise it's true. To help me remember the truth table for this one, I remember it as being exclusively OR, the normal OR gate also includes AND, this one is exclusive to just OR.


A
B
A ^ B
false
false
false
true
false
true
false
true
true
true
true
false

The autonauts implementation for this one is a bit more involved than the previous ones because it requires at least 2 MK 0 bots. I'm going to post 2 versions, one for understanding, and then one for efficiency or resources.

Understanding
I'll refer you to the above code and the schematic for how to implement your programming for the 5 bots.

Efficient
This implementation uses 3 less crates, and 1 less bot, but it's trade off is that the propagation time is a bit longer since the bots actually have to travel in order to switch the output.
The schematics are a bit different for this one, basically there's two bots that handle the True cases, and two bots that handle the False cases. The way that the mechanism works is that there's a single berry, with two different locations, it's kind of similar to a petri net (http://wikipedia) Once the requirements for the gate to turn true are met, then the corresponding bot retrieves the berry from the left crate, and places it into the right crate, then once the gate should turn off, another bot retrieves the berry from the right crate and places it into the left crate.

Name
Description
Berry Storage 1
Input 1
Berry Storage 3
Input 2
Berry Storage 9
Output
Berry Storage 10
Standby Storage

Here is the 4 different bot programs:
Bot 1
Bot 2

Bot 3

Bot 4
How do Computers do Addition?
Next we need to understand how computers do math. When I was in high school I read a book that put base arithmetic in a really easy to understand terminology.

How do we count to 10
Take a second and think about how we count to 10, remember when you were really young? We used our fingers! This forms the basis for our entire counting system, base 10, because we have 10 fingers (including thumbs for simplicity's sake). When we count, we go 0,1,2,3,4,5,6,7,8,9, then 0, carry the 1. And we carry the 1 because the next digit in our number represents the number of completed hand sets we've done. The way computers do math is actually really similar, they just don't have as many fingers as we do.

How do dolphins count to 10
So we all know how to count to 10, but how do dolphins do it? They only have 2 fingers (or fins), well, in this case, they go 0, 1, 0 carry the 1. This is how computers do math! They only have 2 fingers! This is the concept of binary.

Binary Addition
Okay, so now, what does it look like when we do addition of binary? Or dolphin math? Well, I've got a handy dandy table:

A
B
Out
Carry
0
0
0
0
1
0
1
0
0
1
1
0
1
1
0
1

Does this table look familiar? It should, take a look at the XOR truth table again. It's exactly the same! (Well with the carry bit being the AND of the two inputs)
Adder Circuits
Now that I've given you a quick and dirty overview of binary addition, we're ready for implementation in Autonauts!

A Half-Adder
The table I displayed in the last section is actually part of a circuit, known as a half adder, put 2 of them together, and we get out next circuit, the full adder! A half adder can do half a digit (or the least significant digit) of arithmetic.


Now, extending our last XOR build, we can see a half adder:


The crate on the far right is our new carry bit, it reuses the AND Gate we implemented earlier, the rest is identical to the previous section covering our XOR Gate.

A Full-Adder
Okay, so a full adder, is literally two half adders glued together, with one input from the first half adder being the carry bit from the previous digit, and the other being the first input from the user. Then the output of the first half adder is the first input of the second half adder, and the second input is the second input from the user. Then the two Carry outs are ORd together, since 1+1=0 carry the 1, and 1+1+1=1 carry the 1. Don't worry, I've got a table here:

A
B
Carry In
Output
Carry Out
0
0
0
0
0
1
0
0
1
0
0
1
0
1
0
1
1
0
0
1
0
0
1
1
0
1
0
1
0
1
0
1
1
0
1
1
1
1
1
1

Take a look at the schematic:


Okay, time to implement this in autonauts:


Again since we've covered all of these scripts in previous sections, and with the schematic given above, I'm going to have you guys go back and take a look at those to figure out how to implement this.
Putting it all together
So all this is cool, but what does it do? Addition!
If we take a few of these adder circuits and string them together in a daisy chain fashion, we can create, what's called an accumulator, this is a fancy term for a crude CPU, it can take two binary numbers, and add them together.

Lets see if we can make a 4 bit adder, this will take two 4 bit numbers, and add them together to produce the result, see the image below:


Tada! And here's the finished product, it can add any 2 numbers between 0 and 15! (so long as their sum is also between 0 and 15 hehe)


And here it is in action:

6 Comments
iggy12345  [author] Jul 15, 2024 @ 8:30pm 
@dasfire121 everything I've done here is possible with mk1 bots, so absolutely. What you'd want to do is create a bot to monitor your cereal crop storage and when the desired condition is met, then put a berry in a box. From there it should be as simple as following the guide
dasfre121 May 14, 2024 @ 7:38am 
I have a question for how to use AND in a more complex setting. Basically I want to harvest cereal crop if my cereal seed storage, my straw storage, and my cereal storage are all not full, otherwise no harvest. How would that look do you know? And would it be possible with mk2 bots
iggy12345  [author] Feb 23, 2023 @ 10:29am 
Okay the AND gate section is fixed now too
iggy12345  [author] Feb 23, 2023 @ 10:13am 
Okay, I've fixed the youtube links, I'm aware that the AND gate isn't actually correct, I'm going to fix it right now
BenieTheDragon Feb 3, 2023 @ 10:18am 
My head hurts. And yeah, video links are broken too.
Blaze1961 Mar 8, 2022 @ 6:47am 
The video links are broken. "An error occurred. Please try again later. (Playback ID: ZFw-pf6qyIMvvJ6W)"