programgames/sudoku/play.xtl
ᵘp̲uzzle : Unit -> Int
ᵘp̲uzzle ← { @ → n ← ᵖn̲umber "PUZZLE 1 TO 4 ?" (n ≥ 1) ∧ n ≤ 4 ? n◆ ᵘp̲uzzle @ }
Used in: ᵘp̲uzzle, games/sudoku/play.xtl:61
ᵘr̲efused : Num a => a -> b -> Char
Why a move was refused (w from s:w_hy), as the player reads it.
ᵘr̲efused ← { w d → 1 = w ? "ROW, COLUMN AND DIGIT ARE 1 TO 9 (DIGIT 0 CLEARS)" 2 = w ? "THAT CELL IS GIVEN" @ f̲ormat< "{d} IS ALREADY IN THAT ROW, COLUMN OR BOX" }
Used in: ᵘa̲sk
ᵘh̲int : Int -> Char
ᵘh̲int ← { s → h ← ˢh̲int s 0 = f̲irst h ? "A DIGIT IS WRONG SOMEWHERE: THE GRID HAS NO SOLUTION" @ f̲ormat< "TRY ROW {f_irst h} COLUMN {2 s_elect h}: {3 s_elect h}" }
f̲ormat< expands to
"TRY ROW " c̲at (f̲ormat (f̲irst h)) c̲at " COLUMN " c̲at (f̲ormat (2 s̲elect h)) c̲at ": " c̲at (f̲ormat (3 s̲elect h))
Used in: ᵘa̲sk
ᵘc̲ell : Int -> Int -> Char
ᵘc̲ell ← { s rc → k ← 1 + (9 × (f̲irst rc) − 1) + (2 s̲elect rc) − 1 @ f̲ormat< "ROW {f_irst rc} COLUMN {2 s_elect rc}: {w_here k s_elect s:l_egal s}" }
f̲ormat< expands to
"ROW " c̲at (f̲ormat (f̲irst rc)) c̲at " COLUMN " c̲at (f̲ormat (2 s̲elect rc)) c̲at ": " c̲at (f̲ormat (w̲here k s̲elect ˢl̲egal s))
Used in: ᵘa̲sk
ᵘt̲urn : Int -> Char
A turn: the grid, then commands until a move changes it.
ᵘt̲urn ← { s → said ← p̲rint! "" shown ← p̲rint! ˢv̲iew s 1 = ˢs̲tatus s ? "SOLVED!" ᵘa̲sk s }
Used in: ᵘa̲sk, games/sudoku/play.xtl:61
ᵘa̲sk : Int -> Char
A command: a letter (h, c, s, q) or a move, with its numbers. A hint, a cell's candidates or a refusal is printed and asked again.
ᵘa̲sk ← { s → line ← ᵖl̲ine "ROW COL DIGIT, H, C ROW COL, S OR Q ?" v ← ᵖn̲umbersIn line cmd ← (1 + "hHcCsSqQ" i̲ndexOf f̲irst line c̲at " ") d̲iv 2 4 = cmd ? "STOPPED" 3 = cmd ? ᵘs̲olution s 1 = cmd ? s ᵘs̲ay ᵘh̲int s (2 = cmd) ∧ 2 = t̲ally v ? s ᵘs̲ay s ᵘc̲ell v 3 ≠ t̲ally v ? s ᵘs̲ay "TYPE A ROW, A COLUMN AND A DIGIT, OR A LETTER" w ← s ˢw̲hy v 0 = w ? ᵘt̲urn s ˢm̲ove v s ᵘs̲ay w ᵘr̲efused 3 s̲elect v }