librarylib/State.xtl

State: changing items of a game's state vector, shared by the games.

source

ˡu̲pdate : Int -> Int -> Int

function · line 10

Several items of s changed at once: iv is index, value, index, value, ... A table of every position against every index says which items change; the values spread across it say to what.

      ˢ⁼u̲se< "State"
      10 20 30 40 50 ˢu̲pdate 2 0 5 9
10 0 30 40 9
ˡu̲pdate ← { s iv →
  k ← (t̲ally iv) d̲iv 2
  m ← (r̲ange t̲ally s) '= t̲able ((2 × r̲ange k) − 1) s̲elect iv
  v ← ((t̲ally s) c̲at k) r̲eshape (2 × r̲ange k) s̲elect iv
  (s × n̲ot '∨ r̲/₂ m) + '+ r̲/₂ m × v
}

ˡp̲ut : Int -> Int -> Int

function · line 21

The items of s from position p on replaced by v (pv is p, then v).

      ˢ⁼u̲se< "State"
      10 20 30 40 50 ˢp̲ut 2 7 8
10 7 8 40 50
ˡp̲ut ← { s pv →
  p ← f̲irst pv
  v ← 1 d̲rop pv
  ((p − 1) t̲ake s) c̲at v c̲at ((p − 1) + t̲ally v) d̲rop s
}
Used in: ˡp̲ut