Tic-tac-toe: Difference between revisions
Content added Content deleted
(→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: | Line 6,686: | ||
=={{header|J}}== |
=={{header|J}}== |
||
<syntaxhighlight lang="j"> |
<syntaxhighlight lang="j">Until=: {{[F.(u[_2:Z:v)}} NB. apply u until v is true |
||
'Marks State'=:'.OX' ; 10{.1 |
'Marks State'=:'.OX' ; 10{.1 |
||
'`errmsg turn board=: echo@'no'`{.`}. NB. get turn/board from state vector |
'`errmsg turn board=: echo@'no'`{.`}. NB. get turn/board from state vector |
||
Line 6,697: | Line 6,697: | ||
won=: ([:+./[:(3=[:|+/)"1],|:,(<@i.@2|:]),:<@i.@2|:|.)@(3 3$board) |
won=: ([:+./[:(3=[:|+/)"1],|:,(<@i.@2|:]),:<@i.@2|:|.)@(3 3$board) |
||
outcome=: (' wins'echo@,~Marks{~-@t)`(echo@'tie')@.(1:i.~won,full) |
outcome=: (' wins'echo@,~Marks{~-@t)`(echo@'tie')@.(1:i.~won,full) |
||
prompt=: echo@'you''re X''s. enter a move (1–9) each turn' |
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 |
ttt=: outcome@(show@move Until (won+.full))@State@prompt |
||
NB. use: ttt 0 (arg is ignored)</syntaxhighlight> |
NB. use: ttt 0 (arg is ignored)</syntaxhighlight> |
||
Line 6,703: | Line 6,703: | ||
<pre> ttt 0 |
<pre> ttt 0 |
||
you're X's. enter a move (1–9) each turn' |
you're X's. enter a move (1–9) each turn as below:' |
||
1 2 3 |
|||
4 5 6 |
|||
7 8 9 |
|||
. O . |
. O . |