Besiege

Besiege

60 ratings
How to: Logic Gates v1.20
By Uncle Fester
A very basic course in digital electronics, here I will cover the basics about Boolean algebra and circuits with logic gates.
   
Award
Favorite
Favorited
Unfavorite
Introduction
V1.0 brought a gift from the heavens, four blocks that will allow us to sequence and automate various aspects from our machines. but not everyone has knowledge about the different logic gates or the Boolean algebra under which they work.

This guide will cover the basics about Boolean algebra, the different kind of logic gates and a few extra things that will make your life easier.
The Logic Gate Block
Here is the configuration menu of the Logic gate Block.

Input A: up to five different keys or variables*
Input B: up to five different keys or variables*
Logic gate: logic gate type, listed and detailed below
Toggle mode: toggle mode here works for the logic gate imputs, not the output
Emulate: up to five different keys or variables*

In order to put more than one variable in an input or output, they have to be written with a ";" and no spaces between them. As far as I could track, you can put up to 13 variables in one input or output, the only limitation seems to be the thirty character limit in the variable writing box. Here is an example of how variables must be written if you want to use more than one per box:

var1;var2;var3;var4

Be mindfull when using the toggle mode, as it will work with the logic gate inputs only, all circuits below dont use the toggle mode.
The logic gates
OR
The OR logic gate will have a high (1) output, when at least one of its imputs also has a high value. Its formula is A+B=Q.


Input "A"
Input "B"
Output "Q"
0
0
0
1
0
1
0
1
1
1
1
1


AND
The AND logic gate will have a high output, when both its imputs have a high value. Its formula is A×B=Q.


Input "A"
Input "B"
Output "Q"
0
0
0
1
0
0
0
1
0
1
1
1


NOT
The NOT gate, also known as inverter will give the oppostite value of its imput as his output. The formula is A´=Q (the actual simbol would be an A with a line over it, but i didn´t found how to do it)

Input "A"
Output "Q"
0
1
1
0

NOR
The NOR (Not OR) logic gate will have a high (1) output, when both its imputs have a low value. Its formula is (A+B)´=Q.


Input "A"
Input "B"
Output "Q"
0
0
1
1
0
0
0
1
0
1
1
0


NAND
The NAND (Not AND) logic gate will have a high output, when at least one of its imputs has a low value. Its formula is (A×B)´=Q.


Input "A"
Input "B"
Output "Q"
0
0
1
1
0
1
0
1
1
1
1
0


XOR
The XOR (eXclusive OR) logic gate will have a high output, when both imputs have different values. Its formula is A⊕B=Q

Input "A"
Input "B"
Output "Q"
0
0
0
1
0
1
0
1
1
1
1
0


XNOR
The XNOR (eXclusive Not OR) logic gate will have a high output, when both imputs have the same value. Its formula is (A⊕B)´=Q

Input "A"
Input "B"
Output "Q"
0
0
1
1
0
0
0
1
0
1
1
1
Latches and Flip Flops
Maybe one of the most useful thing you can build, these are memory circuits that store a Bit of data. I wont describe the whole theory behind this electronic devices, for that I will leave a link at the end of this section, now I will cover just some basics. Now you just need to know than latches (unlike Flip Flops) dont need a clock to work, they are asynchronous components. Depending on what you are planing to do, one or the other will prove to be more eficient.

SR Latch
One of the most basic memory circuits, there are various ways to build them (with NOR or NAND gates, or even other combinations). When the Set imput has a high value, the Q output will give a high value, and keep it that way until the Reset input recieves a high value. On the design below, if both imputs have a high value, the Latch will become unstable.

The v1.10 update added a SR Latch that avoids the undesired state but doesnt have the negated output, so, you will have to use a NOT gate if you need that output.

SR Latch with NOR gates
Set
Reset
Output "Q"
Output "Q´"
0
0
Keep
Keep
1
0
1
0
0
1
0
1
1
1
NOT desired*
NOT desired*

SR Latches and Flip Flops made with double NAND gates dont work on Besiege (I dont know why), also, the truth table of Latches and FF with double NOR gates is replaced by the truth table of double NAND gates Latches and FF (wierd)

Set
Reset
Output "Q"
0
0
Keep
1
0
1
0
1
0
1
1
0

D Latch
Having only one Data input, this latch will store the current D imput level only when the Enable imput has a high value. A D-latch may be considered as a one-input synchronous SR latch.

This latch will only recieve new information when the clock is in a high value and will only keep it stored when the clock is low.


Data
Enable
Output "Q"
Output "Q´"
X
0
Keep
Keep
0
1
0
1
1
1
1
0


SR Flip Flop
Flip Flops are synchronous bistable components, wich means that all information changes will ocurr onlywhen the Control/Clock imput is in a high value.

With the addition of a SR latch in the V1.10 update, the diagram doesnt change much, you will still need two AND gates and a clock to build this Flip Flop.


Set
Reset
Clock
Output "Q"
Output "Q´"
X
X
0
Keep
Keep
0
0
1
Keep
Keep
1
0
1
1
0
0
1
1
0
1
1
1
1
NOT desired
NOT desired
Besiege note: After testing, if both S and R have a high value (regardless of Q value) R takes priority.


JK Latch
This Latch works the same way as an SR Flip Flop without the Not desired state. When both J and K imputs have a high value, the output will toggle its currente state.

Due to Besiege having all their logic gates limited to only two imputs, building a JK Latch would require twelve different keys, drastically limiting what you could build. Anyway, here I will add the circuit of a JK Latch you could build.











For more detailed information check here[en.wikipedia.org]
Other logic gates options
Besides the addition of the SR Latch an D Latch, the developers added other logic gates for us to try:
  • Counter: a logic gate that needs counts to three input pulses until giving an output at the fourt pulse

  • Random: gives a random high or low output everytime it recieves an input pulse. Regretably if you add variables or more key outputs, it wont select one randomly, its either all of them high or all low. Also, this is the only gate where the Toggle mode works on the output instead of the input.

  • Edge detector: detects the input shifts from low to high or vice versa, only giving a high output in such instances.
Boolean algebra and Karnaugh maps
Now that you know your Boolean operations, this will be your design phase. Now its time for you to make the truth table for your circuit, a truth table includes all posible combinations of the circuit imput variables and the output value (only one output per table, more output variables mean one formula for each one, and thus a different circuit).

Here I will add the laws for making boolean operations.

Law
Expresion
Anullment
a+1=1
a×0=0
Identity
a+0=a
a×1=a
Idempotent
a+a=a
a×a=a
Complement
a+a´=1
a×a´=0
Double negation
(a´)´=a
Associative
(a+b)+c=a+(b+c)
(a×b)×c=a×(b×c)
Commutative
a+b=b+a
a×b=b×a
Distributive
a×(b+c)=(a×b)+(a×c)
a+(b×c)=(a+b)×(a+c)
Absorptive
a+(a×b)=a
a×(a+b)=a


Now comes one of the tricky parts, as there are two complementary ways of deducting the formula from the truth table, those are Minterms (logical AND) and Maxterms (logical OR), as expresed in De Morgan´s theorem.

(A+B)´=A´×B´ and (A×B)´=A´+B´

The objetive is to get the formula to its minimal expresion to simplify the design.

Here is a tiny example

Q= (A+B) × (A+C) A×A + A×C + A×B + B×C Distributive law A + A×C + A×B + B×C Idempotent AND law (A×A = A) A×(1+C) + A.B + B×C Distributive law A×1 + A×B + B×C Identity OR law (1+C=1) A×(1+B) + B×C Distributive law A×1 + B×C Identity OR law (1+B=1) Q= A + B×C

While this is a very small example, now you are using one less OR gate

Here I leave a youtube episodic series of short videos that explains this way better that I ever could

Computer Science - Boolean Algebra
The importance of using a Clock
While the title seems a joke, believe me it wont be when you are trying large scale sequenced actions. A clock is an oscilator wich goes from low to high outputs at a predefined frecuency, the amount of full cycles per second is measured in Hertz (Hz=1/Time).

It is advisable for both high and low states to have the same duration.

So why is this mandatory for large computing and sequences?? because it will synchronize your whole machine, when the clock is in its low state no computing will be done. Be mindfull that you will need an AND gate in each imput conecting it to the clock.

Note: the addition of the edge detector gate opens up more opportunities for better machine synchronization.
Final notes
Besiege brought back memories from my years in highshool and I wanted to share a bit of information with those who dont know anything about electronics but love this game.

If you want to add information to this guide, PM me and I will add you as a colaborator.

To learn about the Level Editor logic basics, check here
https://steamproxy-script.pipiskins.com/sharedfiles/filedetails/?id=1389017451
19 Comments
Uncle Fester  [author] 4 Jul, 2024 @ 3:13pm 
Thanks for reminding me that, its been more than a decade since I used boolean in real world.
mechamonk man 3 Jul, 2024 @ 10:35pm 
Worth noting for anyone simplifying logic that with boolean algebra, you can define outputs that you don't matter to you as "don't care" outputs, which can greatly simplify logic (at the cost of potentially unexpected behavior in the event of a glitch or noisy signal in the real world), since you can essentially treat them as either a zero or one. If you are making something super complicated, then don't care terms can be a big help! Worth looking up/reading about if you have some free time.
Stinningarbrestur 12 Apr, 2022 @ 3:53am 
thankya thankya, my pleasure :3
Uncle Fester  [author] 10 Apr, 2022 @ 4:28pm 
Dude, you are a genius, I tried using ";" but I wrote it with a space after the simbol, I will edit the guide when I have some spare time, thank you
Stinningarbrestur 10 Apr, 2022 @ 3:46pm 
put a ; between them
Uncle Fester  [author] 8 Apr, 2022 @ 2:55pm 
Just checked, just one variable per input on vanilla, if you know how to use multiple variables in on input, I would like to know
Stinningarbrestur 8 Apr, 2022 @ 1:17pm 
Might wanna update a lil bit, since you can in fact use as many variables as you want per input ;) Although eventually the list of variables will escape the text box and you won't be able to see the beginning or end of the list, lol
Uncle Fester  [author] 8 Oct, 2020 @ 8:32pm 
I have some examples in my workshop, like a auto reload catapult and a (simple) target seeking turret, self nivelating drones are easy to do too, but the limit is your own imagination
Sp4m 8 Oct, 2020 @ 6:23pm 
I appreciate the detail of your guide, but I would appreciate if the guide started off with some context. What can we do with this in Besiege?

I found this and your other guide since I'm trying to learn how to make my own Death Race levels.
Uncle Fester  [author] 26 Mar, 2020 @ 1:09pm 
Thanks, I overlooked it