RosettaCodeData/Task/Tic-tac-toe/APL/tic-tac-toe-24.apl
2026-04-30 12:34:36 -04:00

8 lines
838 B
APL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

⎕IO B WM0(2 90)(7 56 448 73 146 292 273 8492) ⍝ the board and winning trios
{_{~:{3::'no''move (1-9): ' ⍝ your move
(B)[M¯1+12]:20 0B[0;M]1}
B[1;Z[?Z~B]]1} ⍝ cpu's move
_{(,' ',)/⎕AV[3 3(⎕AV'.XO')ׯ1B~B]} ⍝ show board after each cpu move
W/3=|B[;]+.WMF511=2B ⍝ test win and full conditions
_{⎕OFF' wins',{W:'XO'[]'the cat'}}(WF) ⍝ when game is over, exit and print winner
~}{0}1 ⍝ now it's the other player's turn