programgames/shut-the-box/shut-the-box.xtl

source · imports b: games/shut-the-box/ShutTheBox.xtl

M : Int

value · line 8
M ← ᵇs̲ubsets @

s : Int

value · line 15
s ← ᵇn̲ew 0

t : Int

value · line 18
t ← s ᵇs̲hut (r̲ange 9) m̲ember? 4 7

ᵘg̲ame : Int -> Int

function · line 27

A whole game by the high-tiles player: each turn shuts the move with the highest tiles. Each line is the box before the roll.

ᵘg̲ame ← { s →
  said ← p̲rint! ᵇv̲iew s
  r ← '+ r̲/ ᵇr̲oll s
  0 = t̲ally s ᵇm̲oves r ? ᵇs̲core s
  t ← s ᵇs̲hut s ᵇh̲igh r
  0 = ᵇs̲core t ? 0
  ᵘg̲ame t
}

ok : Unit

value · line 40
ok ← "512 = 2 s_elect s_hape M" a̲ssert< "every subset of nine tiles"
a̲ssert< expands to
({ @ → (512 = 2 s̲elect s̲hape M) ? @◆ ⎕E̲RR "assertion failed: 512 = 2 s_elect s_hape M (every subset of nine tiles) [games/shut-the-box/shut-the-box.xtl:40]"◆ @ } @)

ok : Unit

value · line 41
ok ← "'& r_/ 7 = (s b:m_oves 7) '+ '* i_nner r_ange 9" a̲ssert< "every move for a 7 adds up to 7"
a̲ssert< expands to
({ @ → ('∧ r̲/ 7 = (s ᵇm̲oves 7) '+ '× i̲nner r̲ange 9) ? @◆ ⎕E̲RR "assertion failed: '& r_/ 7 = (s b:m_oves 7) '+ '* i_nner r_ange 9 (every move for a 7 adds up to 7) [games/shut-the-box/shut-the-box.xtl:41]"◆ @ } @)