Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,58 @@
processor Tic-Tac-Toe
@: [position´1..position´9];
source isWonOrDone
[$@Tic-Tac-Toe(1..3) -> #, $@Tic-Tac-Toe(4..6) -> #, $@Tic-Tac-Toe(7..9) -> #,
$@Tic-Tac-Toe(1..9:3) -> #, $@Tic-Tac-Toe(2..9:3) -> #, $@Tic-Tac-Toe(3..9:3) -> #,
$@Tic-Tac-Toe([1,5,9]) -> #, $@Tic-Tac-Toe([3,5,7]) -> #
] -> \(
when <=[]?($@Tic-Tac-Toe <~[<position>]>)> do 'draw' !
when <~=[]> do $(1) !
\) !
when <[<mark>+ VOID]?($ <[<=$(first)>+ VOID]>)> do '$(first); wins!'!
end isWonOrDone
source validMoves
$@Tic-Tac-Toe -> \[i](<position> $ !\) !
end validMoves
templates move
when <?($@Tic-Tac-Toe($.position::raw) <position>)> do @Tic-Tac-Toe($.position::raw): $.mark;
$ !
otherwise
'Incorrect move$#10;' -> !OUT::write
end move
source showString
'$:1..9:3 -> '$#10;$@Tic-Tac-Toe($..$+2)...;';$#10;' !
end showString
end Tic-Tac-Toe
composer toInt
<INT>
end toInt
source play
def board: $Tic-Tac-Toe;
@: mark´'X';
templates getMove
[] -> #
when <=[]> do
$board::showString -> !OUT::write
'$@play; to move $board::validMoves;:$#10;' -> !OUT::write
[{mark: $@play, position: $IN::readline -> toInt} -> board::move] -> #
otherwise
$(1) !
end getMove
$getMove -> #
when <{}> do
'$.mark; played $.position;$#10;' -> !OUT::write
@: $@ -> \(<=mark´'X'> mark´'O'! <=mark´'O'> mark´'X' !\);
[$board::isWonOrDone] -> \(
when <=[]> do $getMove!
otherwise '$(1);$#10;' -> !OUT::write
\) -> #
end play
$play -> !VOID