sourcegames/shut-the-box/play.xtl

1⍝!/usr/bin/env xetal 2⍝# Shut the box at the terminal: roll, then type the tiles to shut 3⍝# (they must add up to the roll, for example "2 5"). The moves you have 4⍝# are listed each turn. The game ends when no open tiles make the roll; 5⍝# the open tiles are your score, and shutting them all wins. The rules 6⍝# are those of ShutTheBox.xtl. 7ᵇ⁼u̲se< "ShutTheBox" 8ᵖ⁼u̲se< "Play" 9ˣ⁼u̲se< "Text" 10said ← p̲rint! "SHUT THE BOX" 11 12⍝# The tiles typed, as a 0/1 vector of 9, if they are one of the moves; 13⍝# else it asks again. 14ᵘa̲sk ← { m → 15 want ← (r̲ange 9) m̲ember? ᵖn̲umbers "TILES TO SHUT ?" 16 '∨ r̲/ '∧ r̲/₂ m = ((t̲ally m) c̲at 9) r̲eshape want ? want◆ ᵘa̲sk m 17} 18⍝# A turn: the box, the roll, the moves; shut, until stuck or shut. 19ᵘt̲urn ← { s → 20 said ← p̲rint! "" 21 said ← p̲rint! ᵇv̲iew s 22 d ← ᵇr̲oll s 23 r ← '+ r̲/ d 24 said ← p̲rint! @ f̲ormat< "YOU ROLL {d}: {r}"
f̲ormat< expands to
("YOU ROLL " c̲at (f̲ormat (d)) c̲at ": " c̲at (f̲ormat (r)))
25 m ← s ᵇm̲oves r 26 0 = t̲ally m ? @ f̲ormat< "NO MOVE. YOUR SCORE: {b:s_core s}"
f̲ormat< expands to
("NO MOVE. YOUR SCORE: " c̲at (f̲ormat (ᵇs̲core s)))
27 said ← p̲rint! "MOVES:" 28 listed ← ˣl̲ines ᵇl̲isted m 29 t ← s ᵇs̲hut ᵘa̲sk m 30 0 = ᵇs̲core t ? "YOU SHUT THE BOX!" 31 ᵘt̲urn t 32} 33ᵘt̲urn ᵇn̲ew 0