sourcelib/State.xtl
1⍝# State: changing items of a game's state vector, shared by the games.
2
3⍝ :: Int -> Int -> Int
4⍝# Several items of s changed at once: iv is index, value, index, value,
5⍝# ... A table of every position against every index says which items
6⍝# change; the values spread across it say to what.
7⍝# >> "s:" u_se< "State"
8⍝# >> 10 20 30 40 50 s:u_pdate 2 0 5 9
9⍝# 10 0 30 40 9
10ˡu̲pdate ← { s iv →
11 k ← (t̲ally iv) d̲iv 2
12 m ← (r̲ange t̲ally s) '= t̲able ((2 × r̲ange k) − 1) s̲elect iv
13 v ← ((t̲ally s) c̲at k) r̲eshape (2 × r̲ange k) s̲elect iv
14 (s × n̲ot '∨ r̲/₂ m) + '+ r̲/₂ m × v
15}
16⍝ :: Int -> Int -> Int
17⍝# The items of s from position p on replaced by v (pv is p, then v).
18⍝# >> "s:" u_se< "State"
19⍝# >> 10 20 30 40 50 s:p_ut 2 7 8
20⍝# 10 7 8 40 50
21ˡp̲ut ← { s pv →
22 p ← f̲irst pv
23 v ← 1 d̲rop pv
24 ((p − 1) t̲ake s) c̲at v c̲at ((p − 1) + t̲ally v) d̲rop s
25}