Skip to content

Instantly share code, notes, and snippets.

@pitust
Created March 11, 2022 14:57
Show Gist options
  • Save pitust/22cf98f67d804327d59837dd2dc72ec9 to your computer and use it in GitHub Desktop.
Save pitust/22cf98f67d804327d59837dd2dc72ec9 to your computer and use it in GitHub Desktop.

The exchange protocol

Constants

  1. ns mask is 0xffff_0000_0000
  2. magic is 0x4e96_0000_0000
  3. mask is 0x0000_ff00_0000
  4. data mask is 0x0000_00ff_ffff
  5. class mask is 0x0000_f000_0000
  6. kClassDefault is 0x0000_0000_0000
  7. kClassSupply is 0x0000_1000_0000
  8. kClassDemand is 0x0000_2000_0000
  9. kIdleEmpty is 0x0000_0100_0000
  10. kIdleFull is 0x0000_0200_0000
  11. kSupplyFromCore is 0x0000_1100_0000
  12. kSupplyFromBlock is 0x0000_1200_0000
  13. kSupplyToPoint is 0x0000_2000_0000
  14. encodePoint(x, y) is (x << 12) | (y << 0)

Definition

  1. each proc assumes a role, :producer or :consumer, based on build --target
  2. If consumer
    1. for unit in $transferUnitOfChoice
      1. if unit not controlled || unit flag & ns mask = magic
        1. if unit flag & mask != magic
          1. set flag tokIdleEmpty
        2. if unit flag = kIdleEmpty
          1. set flag to kSupplyFromCore
          2. goto core
        3. if unit flag & class mask = kClassSupply and unit near core
          1. take stuff from core
          2. set flag to kSupplyToPoint | current cap
          3. goto @this
        4. if unit flag & mask = kSupplyToPoint and unit flag & datamask < current cap
          1. set flag to kSupplyToPoint | current cap
          2. goto @this
        5. if unit near @this and unit flag & mask = kSupplyToPoint
          1. take this goods if unit flag & datamask < 10 or current cap > 10
        6. if unit empty
          1. set flag to kIdleEmpty
        7. if unit flag = kIdleFull
          1. set flag to kSupplyToPoint | current cap
          2. goto @this
  3. If producer
    1. for unit in $transferUnitOfChoice
      1. if unit not controlled || unit flag & ns mask magic
        1. if unit flag & mask != magic
          1. set flag tokIdleEmpty
        2. if unit flag & mask = kSupplyFromCore
          1. if dist(unit, core) >= dist(unit, @this)
            1. set flag to kSupplyFromBlock | encodePoint(@thisx, @thisy)
            2. goto @this
        3. if unit flag & mask = kSupplyFromBlock
          1. Let p be decodePoint(unit flag & data mask)
          2. if dist(unit, p) < dist(unit, @this)
            1. set flag to kSupplyFromBlock | encodePoint(@thisx, @thisy)
            2. goto @this
        4. if unit flag & class mask = kClassSupply and unit near @this
          1. put shit into the unit
          2. set flag to kIdleFull
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment