[skip all navigation]

Cyclical Countoffs, Reducing that trigger count!

Creator: jjf28
Time: Feb 9 2012, 11:18 pm

Post #1     jjf28 Feb 9 2012, 11:18 pm

[Avatar]
Relax.
offlinecontact
Rank: Regular
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).

Code

           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








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



Bit more math...

(user posted image)


C*(2n-1 - 1) + 2n – C
= C*2n-1 + 2n – 2 - C
= C*2n/2 + 2n/4 - C

Pn = 2 * Pn - 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
This post was edited 10 times, last edit by jjf28: Feb 12 2012, 1:42 am.

Rs_yes-im4real@USEast - Clan KHD - Helms Deep Home
Top

Post #2     Tuxlar Feb 9 2012, 11:37 pm

[Avatar]
offlinecontact
Rank: Veteran
Interesting. Problem is, why would you want to use less triggers for a countoff? I can't imagine you ever needing more than a handful for any given countoff anyway...

Problem solver.
Top

Post #3     Lanthanide Feb 9 2012, 11:38 pm

[Avatar]
offlinecontact
Rank: Regular
Quote from jjf28
Description:None specified.
Players:
  • Player 1
  • Conditions:
  • Current player accumulates at least 18 gas.
  • Actions:
  • Set Resources for current player: Add 18 minerals.
  • Set Resources for current player: Subtract 18 gas.
  • Preserve trigger.
  • Shouldn't this be:

    Description:None specified.
    Players:
  • Player 1
  • Conditions:
  • Current player accumulates at least 18 gas.
  • Current player accumulates at most 37 gas.
  • Actions:
  • Set Resources for current player: Add 18 minerals.
  • Set Resources for current player: Subtract 18 gas.
  • Preserve trigger.

  • O)FaRTy1billion -- "Lanthanide -- surely you have photos of yourself dressed up as a girl, az?" I don't have pictures of me dressed up as a girl.
    O)FaRTy1billion -- One time I was jumping on a trampoline (at that very friend's house xD) with water balloons in my shirt held up by a belt.
    Azrael.Wrath -- ...
    Top

    Post #4     jjf28 Feb 9 2012, 11:38 pm

    [Avatar]
    Relax.
    offlinecontact
    Rank: Regular
    A single countoff is never really an issue, it's when you are using many (for something like variable multiplication) that they can get quite bulky

    ah yes, ty lanth

    Rs_yes-im4real@USEast - Clan KHD - Helms Deep Home
    Top

    Post #5     Lanthanide Feb 9 2012, 11:42 pm

    [Avatar]
    offlinecontact
    Rank: Regular
    Quote from Tuxedo-Templar
    Interesting. Problem is, why would you want to use less triggers for a countoff? I can't imagine you ever needing more than a handful for any given countoff anyway...
    In my map I have a set of countoffs for almost all buildable buildings, including addons. For most of them I support up to 63 buildings, so require 6 triggers per building type using binary countoffs. Using the 1,3,8,18,38 sequence I can reduce this to 5 triggers that support up to 77 buildings.

    Also in my map I actually want to split the spawning over 2 trigger cycles, so using these countoffs gives me that behaviour as well as using fewer triggers to accomplish it.


    Edit: jjf, the triggers are still a bit screwy, the 8 one says "at most 18" when it should be 17, and the 3 one says "at most 17" when it should be 7.

    O)FaRTy1billion -- "Lanthanide -- surely you have photos of yourself dressed up as a girl, az?" I don't have pictures of me dressed up as a girl.
    O)FaRTy1billion -- One time I was jumping on a trampoline (at that very friend's house xD) with water balloons in my shirt held up by a belt.
    Azrael.Wrath -- ...
    Top

    Post #6     TiKels Feb 12 2012, 1:32 am

    [Avatar]
    offlinecontact
    Rank: Regular
    Quote from jjf28
    Shoutouts: Lanthanide, TiKels, and Roy for a bit of help finding patterns in the numbers http://www.staredit.net/?p=shoutbox&start_shout=871437
    D'awwww I was just screwing around. The concept of your system interested me (and I mean why wouldn't it, it's so obvious yet so clever). I just saw the pattern and figured I'd blab it in the spambox. Thanks <3

    Top
    0 members in this topic (italic members are currently writing a reply): None
    + guest(s)


    [05:14 am]
    RIVE -- I pray to Mozzarella because I fear the Rapture.
    [04:42 am]
    jjf28 -- it's evil, pure, demonic, evil
    [04:42 am]
    jjf28 -- nothin' holy bout dat holey cheese
    [04:22 am]
    Dem0n -- also get on skype XD
    [04:21 am]
    Dem0n -- I'm curently eating pepper jack cheese :O
    [04:18 am]
    lil-Inferno -- Only Swiss cheese is holy
    [04:18 am]
    Dem0n -- WUT EAT]\
    Please log in to shout.