programgames/2048/play.xtl
ᵘa̲sk : Any a => a -> Int
A direction (1 left, 2 right, 3 up, 4 down) from the first of a d w s on the line, 0 for q; anything else is asked for again.
ᵘa̲sk ← { s → k ← "MOVE (A D W S, Q TO STOP) ?" ᵖl̲etter "adwsADWSqQ" k ≤ 8 ? 1 + (k − 1) m̲od 4 k ≤ 10 ? 0◆ ᵘa̲sk s }
ᵘt̲urn : (Num a, Truthy a) => a -> Char
A turn: the score and board, a move, until the game ends.
ᵘt̲urn ← { s → said ← p̲rint! "" said ← p̲rint! @ f̲ormat< "SCORE {t:s_core s}" shown ← p̲rint! ᵗb̲oard s 1 = ᵗs̲tatus s ? @ f̲ormat< "2048! YOU WIN WITH {t:s_core s}" 2 = ᵗs̲tatus s ? @ f̲ormat< "NO MOVES LEFT. SCORE {t:s_core s}" d ← ᵘa̲sk s 0 = d ? @ f̲ormat< "STOPPED WITH SCORE {t:s_core s}" next ← s ᵗm̲ove d next m̲atch s ? ᵘt̲urn ᵘs̲tuck s◆ ᵘt̲urn next }
Used in: ᵘt̲urn, games/2048/play.xtl:33