Tic-tac-toe: Difference between revisions

Content deleted Content added
Line 979: Line 979:
To subsequent j poster: replacing this entry is fine by me.
To subsequent j poster: replacing this entry is fine by me.
<lang J>
<lang J>
NB. ttt adjudicates.
NB. use: 'XO' ttt 'abcdefghijklmnop'
NB. use: 'XO' ttt 'abcdefghijklmnop'

NB. ttt adjudicates but does not play.
while=: conjunction def 'u ^: v ^:_' NB. j needs to know while is a conjunction
ttt=: [: outcome [: display@:move^:continue^:_ display@:prepare

ttt=: outcome@:((display@:move) while undecided)@:display@:prepare


outcome=: {&(>;:'kitty VICTORY')@:won
outcome=: {&(>;:'kitty VICTORY')@:won
move=: post locate
move=: post locate
continue=: won nor filled
undecided=: won nor filled
prepare=: , 9&{.
prepare=: , 9&{. NB. form the state vector
display=: show [: (1 1,:5 5)&(];.0)@:": [: <"0 fold
display=: show [: (1 1,:5 5)&(];.0)@:": [: <"0 fold


Line 1,019: Line 1,022:


Note 'wrapped example to better fit wide display'
Note 'wrapped example to better fit wide display'
The state vector is 11 items long with
mark of the next player, mark of other player, 9 characters representing the board


NB. play the game -->cell for -? -->cell for -?
NB. play the game -->cell for -? -->cell for -?