programgames/shut-the-box/play.xtl

source · imports b: games/shut-the-box/ShutTheBox.xtl; p: lib/Play.xtl; x: lib/Text.xtl

said : Char

value · line 10
said ← p̲rint! "SHUT THE BOX"

ᵘa̲sk : Truthy a => a -> a

function · line 14

The tiles typed, as a 0/1 vector of 9, if they are one of the moves; else it asks again.

ᵘa̲sk ← { m →
  want ← (r̲ange 9) m̲ember? ᵖn̲umbers "TILES TO SHUT ?"
  '∨ r̲/ '∧ r̲/₂ m = ((t̲ally m) c̲at 9) r̲eshape want ? want◆ ᵘa̲sk m
}

ᵘt̲urn : Int -> Char

function · line 19

A turn: the box, the roll, the moves; shut, until stuck or shut.

ᵘt̲urn ← { s →
  said ← p̲rint! ""
  said ← p̲rint! ᵇv̲iew s
  d ← ᵇr̲oll s
  r ← '+ r̲/ d
  said ← p̲rint! @ f̲ormat< "YOU ROLL {d}: {r}"
  m ← s ᵇm̲oves r
  0 = t̲ally m ? @ f̲ormat< "NO MOVE. YOUR SCORE: {b:s_core s}"
  said ← p̲rint! "MOVES:"
  listed ← ˣl̲ines ᵇl̲isted m
  t ← s ᵇs̲hut ᵘa̲sk m
  0 = ᵇs̲core t ? "YOU SHUT THE BOX!"
  ᵘt̲urn t
}
f̲ormat< expands to
("YOU ROLL " c̲at (f̲ormat (d)) c̲at ": " c̲at (f̲ormat (r)))
f̲ormat< expands to
("NO MOVE. YOUR SCORE: " c̲at (f̲ormat (ᵇs̲core s)))