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

7 lines
639 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 T W WM0(90)¯1 0(7 56 448 73 146 292 273 8492) ⍝ board; turn; win flag; winning trios
_{B[{1=T:{3::'no''move (1-9): ' ⍝ your move
B[P¯1+12]=0:P20 0}
Z[?Z0=B]}]TT-T ⍝ cpu's move; switch turn
' '(,' ',)/3 3'.XO'[0 1 ¯1B] ⍝ show board
}{(~0B)W/3=|B+.WM} ⍝ repeat until won or full
W:'XO'[1=T],' wins''tie'} ⍝ print result