programgames/tic-tac-toe/play.xtl

source · imports t: games/tic-tac-toe/TicTacToe.xtl; p: lib/Play.xtl

said : Char

value · line 8
said ← p̲rint! "TIC-TAC-TOE: YOU ARE X."

ᵘa̲sk : Num a => a -> Int

function · line 11

Your move: the number of an empty square, or it asks again.

ᵘa̲sk ← { b →
  k ← "YOUR MOVE (1-9) ?" ᵖl̲etter "123456789"
  (k ≤ 9) ∧ 0 = k s̲elect b c̲at 1 ? k◆ ᵘa̲sk b
}
Used in: ᵘa̲sk, ᵘy̲ou

ᵘv̲erdict : Num a => a -> Char

function · line 15
ᵘv̲erdict ← { b → d̲isclose (ᵗs̲tatus b) s̲elect "YOU WIN!" "I WIN." "A DRAW." }
Used in: ᵘy̲ou

ᵘy̲ou : (Num a, Truthy a) => a -> Char

function · line 18

You, then the computer, until the game is over.

ᵘy̲ou ← { b →
  said ← p̲rint! ""
  shown ← p̲rint! ᵗv̲iew b
  pic ← ⎕S̲HOW ᵗp̲icture b
  0 < ᵗs̲tatus b ? ᵘv̲erdict b
  ᵘm̲e b ᵗm̲ove ᵘa̲sk b
}

ᵘm̲e : (Num a, Truthy a) => a -> Char

function · line 25
ᵘm̲e ← { b →
  0 < ᵗs̲tatus b ? ᵘy̲ou b
  k ← ᵗa̲i b
  said ← p̲rint! @ f̲ormat< "I TAKE {k}"
  ᵘy̲ou b ᵗm̲ove k
}
f̲ormat< expands to
("I TAKE " c̲at (f̲ormat (k)))
Used in: ᵘy̲ou