Binary Countoffs

From Staredit Network Wiki
Jump to: navigation, search

A binary countoff is used to move the value of one counter to another counter with as few triggers as possible. It is important to know how the binary, or base 2, number system works. The reason for knowing how binary works is to help you understand how this trigger system works.

Triggers

StarCraft Trigger [template]
Players:
  • Neutral
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.

StarCraft Trigger [template]
Players:
  • Neutral
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.

StarCraft Trigger [template]
Players:
  • Neutral
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.

StarCraft Trigger [template]
Players:
  • Neutral
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.

StarCraft Trigger [template]
Players:
  • Neutral
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:

StarCraft Trigger [template]
Players:
  • Neutral
Conditions:
  • Current player accumulates at least 2^x gas.
Actions:
  • Preserve trigger.
  • Set Resources for current player: Add 2^x minerals.
  • Set Resources for current player: Subtract 2^x gas.

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 arithmetic, or almost anything else.