Tic-tac-toe: Difference between revisions
→J: Add number display for selecting squares
(→J: Hopefully improved formatting) Tags: Mobile edit Mobile web edit |
(→J: Add number display for selecting squares) Tags: Mobile edit Mobile web edit |
||
Line 6,686:
=={{header|J}}==
<syntaxhighlight lang="j">
'Marks State'=:'.OX' ; 10{.1
'`errmsg turn board=: echo@'no'`{.`}. NB. get turn/board from state vector
Line 6,697:
won=: ([:+./[:(3=[:|+/)"1],|:,(<@i.@2|:]),:<@i.@2|:|.)@(3 3$board)
outcome=: (' wins'echo@,~Marks{~-@t)`(echo@'tie')@.(1:i.~won,full)
prompt=: echo@:>:@i.@3 3@echo@'you''re X''s. enter a move (1–9) each turn as below:'
ttt=: outcome@(show@move Until (won+.full))@State@prompt
NB. use: ttt 0 (arg is ignored)</syntaxhighlight>
Line 6,703:
<pre> ttt 0
you're X's. enter a move (1–9) each turn as below:'
1 2 3
4 5 6
7 8 9
. O .
|