Binary Countoffs are “used to move the value of one counter to another counter with as few triggers as possible” in one trigger cycle. Often times, especially when using hyper triggers (which run 11.9 times per second), you can wait more than one trigger cycle for your Countoffs to complete…
In such cases you probably wish to use less triggers, but are unsure what numbers would be best to use, and how many cycles a set of numbers would take, the sequences below should help you find an optimal solution (n = Countoff number).
n: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ... nth
One cycle: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 ... 2n-1
Two cycles: 1, 3, 8, 18, 38, 78, 158, 318, 638, 1278, 2558, 5118 ... 2*2n-1 + 2n-2 - 2
Three cycles: 1, 4, 11, 25, 53, 109, 221, 445, 893, 1789, 3581, 7165 ... 3*2n-1 + 2n-2 - 3
Four cycles: 1, 5, 14, 32, 68, 140, 284, 572, 1148, 2300, 4604 ... 4*2n-1 + 2n-2 - 4
C cycles: 1, C+1, 3C+2, 7C+4, 15C+8 ... C*(2n-1 - 1) + 2n - C
Note: adding cycles yields diminishing returns.The maximum value your sequence can handle = 2*(highest number in sequence)+1
Example case & triggers:I can wait two trigger cycles, and my first counter can get as high as 45
So i'll use 1, 3, 8, 18, and 38 as countoffs...
Triggers
Collapse Box
Player 1Current player accumulates at least 38 gas.Set Resources for current player: Add 38 minerals.Set Resources for current player: Subtract 38 gas.Preserve trigger. Player 1Current player accumulates at least 18 gas.Current player accumulates at most 37 gas.Set Resources for current player: Add 18 minerals.Set Resources for current player: Subtract 18 gas.Preserve trigger. Player 1Current player accumulates at least 8 gas.Current player accumulates at most 17 gas.Set Resources for current player: Add 8 minerals.Set Resources for current player: Subtract 8 gas.Preserve trigger. Player 1Current player accumulates at least 3 gas.Current player accumulates at most 7 gas.Set Resources for current player: Add 3 minerals.Set Resources for current player: Subtract 3 gas.Preserve trigger. Player 1Current player accumulates at least 1 gas.Current player accumulates at most 2 gas.Set Resources for current player: Add 1 minerals.Set Resources for current player: Subtract 1 gas.Preserve trigger. Haven’t got around to finishing a proof yet (eww, sets!) but it checks out with brute force tests, feel free to try it yourself!
Brute Force Test Code
Collapsable Box
public class countoffz {
/** Built to run in Eclipse
*
* Currently setup for two cycles
*
* Setup as is to aid visualization
*/
public static void main(String[] args) {
String error="No Errors";
int count=8000, m=0, a=0;
int cycles// Input Cycles Here
= 2 ;
while(count>0){
a=0;
count = count - 1;
m = count;
System.out.print(m);
for(int cyc=0;cyc<cycles;cyc++){
if(m>=5118){
m = m - 5118;
a = a + 5118;
System.out.print("-5118");
}
if(m>=2558 && m<5118){
m = m - 2558;
a = a + 2558;
System.out.print("-2558");
}
if(m>=1278 && m<2558){
m = m - 1278;
a = a + 1278;
System.out.print("-1278");
}
if(m>=638 && m<1278){
m = m - 638;
a = a + 638;
System.out.print("-638");
}
if(m>=318 && m<638){
m = m - 318;
a = a + 318;
System.out.print("-318");
}
if(m>=158 && m<318){
m = m - 158;
a = a + 158;
System.out.print("-158");
}
if(m>=78 && m<158){
m = m - 78;
a = a + 78;
System.out.print("-78");
}
if(m>=38 && m<78){
m = m - 38;
a = a + 38;
System.out.print("-38");
}
if(m>=18 && m<38){
m = m - 18;
a = a + 18;
System.out.print("-18");
}
if(m>=8 && m<18){
m = m - 8;
a = a + 8;
System.out.print("-8");
}
if(m>=3 && m<8){
m = m - 3;
a = a + 3;
System.out.print("-3");
}
if(m>=1 && m<3){
m = m - 1;
a = a + 1;
System.out.print("-1");
}
if(cyc==0){System.out.print("...");}
}
if(count!=a){
error = (" error at " + count);
System.out.println(error);
}
else{System.out.println();}
}
System.out.print(error);
}
}
Bit more math...
C*(2n-1 - 1) + 2n – C
= C*2n-1 + 2n – 2 - C
= C*2n/2 + 2n/4 - C
P
n = 2 * P
n - 1 + C
Shoutouts: Lanthanide, TiKels, and Roy for a bit of help finding patterns in the numbers
http://www.staredit.net/?p=shoutbox&start_shout=871437
Post has been edited 10 time(s), last time on Feb 12 2012, 1:42 am by jjf28.
TheNitesWhoSay - Clan Aura -
githubReached the top of StarCraft theory crafting 2:12 AM CST, August 2nd, 2014.