Jump to content

Tic-tac-toe: Difference between revisions

→‎{{header|Tailspin}}: update to stricter typing
(Added Forth entry)
(→‎{{header|Tailspin}}: update to stricter typing)
Line 13,794:
<lang tailspin>
processor Tic-Tac-Toe
@: [position´1..9 -> (position:$) -> $::value´9];
 
source isWonOrDone
Line 13,801:
$@Tic-Tac-Toe([1,5,9]) -> #, $@Tic-Tac-Toe([3,5,7]) -> #
] -> \(
when <=[]?($@Tic-Tac-Toe <~[<1..9position>]>)> do 'draw' !
when <~=[]> do $(1) !
\) !
when <[<mark>+ VOID]?($ <[<=$(first)::raw>+ VOID]>)> do '$(first); wins!'!
end isWonOrDone
 
source validMoves
$@Tic-Tac-Toe -> \[i](<1..9position> $ !\) !
end validMoves
 
Line 13,829:
source play
def board: $Tic-Tac-Toe;
@: mark´'X';
templates getMove
[] -> #
Line 13,837:
[{mark: $@play, position: $IN::readline -> toInt} -> board::move] -> #
otherwise
$(1) !
end getMove
 
Line 13,843:
when <{}> do
'$.mark; played $.position;$#10;' -> !OUT::write
@: $@ -> \(<=mark´'X'> mark´'O'! <=mark´'O'> mark´'X' !\);
[$board::isWonOrDone] -> \(
when <=[]> do $getMove!
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.