Jump to content

Tic-tac-toe: Difference between revisions

→‎J: Hopefully improved formatting
(→‎J: Made the output readable; coded the game to common expectations (e.g., display X’s/O’s) to avoid confusion; removed unnecessary naming of trivial functions.)
Tags: Mobile edit Mobile web edit
(→‎J: Hopefully improved formatting)
Tags: Mobile edit Mobile web edit
Line 6,686:
 
=={{header|J}}==
<syntaxhighlight lang="j"> Until=: {{[F.(u[_2:Z:v)}} NB. apply u until v is true
Until=: {{[F.(u[_2:Z:v)}} NB. apply u until v is true
'Marks State'=:'.OX' ; 10{.1
'`errmsg turn board=: echo@'no'`{.`}. NB. get turn/board from state vector
Line 6,700 ⟶ 6,699:
prompt=: echo@'you''re X''s. enter a move (1–9) each turn'
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>
Sample play:
 
<pre> ttt 0
you're X's. enter a move (1–9) each turn'
 
Line 6,758 ⟶ 6,755:
X O O
 
X wins</pre>
 
=={{header|Java}}==
16

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.