sourcegames/tic-tac-toe/play.xtl

1⍝!/usr/bin/env xetal 2⍝# Tic-tac-toe at the terminal: you are X and move first; type the number 3⍝# of an empty square. The computer plays O with the quick player of 4⍝# TicTacToe.xtl (it wins when it can, blocks, takes the center, then a 5⍝# corner; a fork can beat it). 6ᵗ⁼u̲se< "TicTacToe" 7ᵖ⁼u̲se< "Play" 8said ← p̲rint! "TIC-TAC-TOE: YOU ARE X." 9 10⍝# Your move: the number of an empty square, or it asks again. 11ᵘa̲sk ← { b → 12 k ← "YOUR MOVE (1-9) ?" ᵖl̲etter "123456789" 13 (k ≤ 9) ∧ 0 = k s̲elect b c̲at 1 ? k◆ ᵘa̲sk b 14} 15ᵘv̲erdict ← { b → d̲isclose (ᵗs̲tatus b) s̲elect "YOU WIN!" "I WIN." "A DRAW." } 16 17⍝# You, then the computer, until the game is over. 18ᵘy̲ou ← { b → 19 said ← p̲rint! "" 20 shown ← p̲rint! ᵗv̲iew b 21 pic ← ⎕S̲HOW ᵗp̲icture b 22 0 < ᵗs̲tatus b ? ᵘv̲erdict b 23 ᵘm̲e b ᵗm̲ove ᵘa̲sk b 24} 25ᵘm̲e ← { b → 26 0 < ᵗs̲tatus b ? ᵘy̲ou b 27 k ← ᵗa̲i b 28 said ← p̲rint! @ f̲ormat< "I TAKE {k}"
f̲ormat< expands to
("I TAKE " c̲at (f̲ormat (k)))
29 ᵘy̲ou b ᵗm̲ove k 30} 31ᵘy̲ou ᵗn̲ew 0