![Table of contents [*]](/skins/2/images/wiki_toc.png)
Binary Countoffs
BinaryIt is important to know how the binary, or base 2, number system works. You can learn about binary in-depth from the Wikipedia article. The reason for knowing how binay works is to help you understand how this trigger system works.Binary CountoffA binary countoff is used to move the value of one counter to another counter with as few triggers as possible.These are triggers that will transfer a number from gas (up to 31 at a time in this example), to minerals. Code=Conditions= -Current player accumulates at least 16 gas. =Actions= -Preserve trigger. -Set Resources for current player: Add 16 minerals. -Set Resources for current player: Subtract 16 gas --- =Conditions= -Current player accumulates at least 8 gas. =Actions= -Preserve trigger. -Set Resources for current player: Add 8 minerals. -Set Resources for current player: Subtract 8 gas --- =Conditions= -Current player accumulates at least 4 gas. =Actions= -Preserve trigger. -Set Resources for current player: Add 4 minerals. -Set Resources for current player: Subtract 4 gas --- =Conditions= -Current player accumulates at least 2 gas. =Actions= -Preserve trigger. -Set Resources for current player: Add 2 minerals. -Set Resources for current player: Subtract 2 gas =Conditions= -Current player accumulates at least 1 gas. =Actions= -Preserve trigger. -Set Resources for current player: Add 1 minerals. -Set Resources for current player: Subtract 1 gas As you can see the triggers take this form: Where x keeps going down until it reaches 0. In the previous example x goes from 4 to 0. Notice that the numbers are powers of 2 (1, 2, 4, 8, 16, etc) in reverse order. In order to calculate the maximum number transferable per trigger run, take the sum of the same value from each trigger. A simpler way to calculate it would be to take the next power of 2 higher than the highest power of 2 in the countoff (2^5 in the example) and subtract 1. In the above case, 31 gas will be converted into minerals per trigger run. Because of the use of powers of two in the order shown, any number between 0 and 31 can be transferred in one trigger cycle with just these 5 triggers. Adding more triggers increases the number range exponentially. A binary countoff like this can be useful for various things, such as counter arithmatic, or almost anything else. |