Skip to content

Instantly share code, notes, and snippets.

@OnorioCatenacci
Created November 3, 2020 21:16
Show Gist options
  • Save OnorioCatenacci/26506d8c0eb7d54b20f2416118b15a0a to your computer and use it in GitHub Desktop.
Save OnorioCatenacci/26506d8c0eb7d54b20f2416118b15a0a to your computer and use it in GitHub Desktop.
Initial state of TicTacToe Game
--------------------------- MODULE TicTacToeGame ---------------------------
VARIABLE boardPositions, turn
tokens == {"X","O","V","-"} (* V == "Vacant", - == "Doesn't matter" *)
row == <<tokens, tokens, tokens>>
grid == <<row, row, row>>
col_1_Win(token) == <<
<<token, "-", "-">>,
<<token, "-", "-">>,
<<token, "-", "-">>
>>
col_2_Win(token) == <<
<<"-", token, "-">>,
<<"-", token, "-">>,
<<"-", token, "-">>
>>
col_3_Win(token) == <<
<<"-", "-", token>>,
<<"-", "-", token>>,
<<"-", "-", token>>
>>
row_1_Win(token) == <<
<<token, token, token>>,
<<"-", "-", "-">>,
<<"-", "-", "-">>
>>
row_2_Win(token) == <<
<<"-", "-", "-">>,
<<token, token, token>>,
<<"-", "-", "-">>
>>
row_3_Win(token) == <<
<<"-", "-", "-">>,
<<"-", "-", "-">>,
<<token, token, token>>
>>
dexterWin(token) == <<
<<token, "-", "-">>,
<<"-", token, "-">>,
<<"-", "-", token>>
>>
sinisterWin(token) == <<
<<"-", "-", token>>,
<<"-", token, "-">>,
<<token, "-", "-">>
>>
PlayerWin(token) == \/ boardPositions = col_1_Win(token)
\/ boardPositions = col_2_Win(token)
\/ boardPositions = col_3_Win(token)
\/ boardPositions = row_1_Win(token)
\/ boardPositions = row_2_Win(token)
\/ boardPositions = row_3_Win(token)
\/ boardPositions = dexterWin(token)
\/ boardPositions = sinisterWin(token)
GameInit == /\ boardPositions \in <<
<<"V","V","V">>,
<<"V","V","V">>,
<<"V","V","V">>
>>
/\ turn = 0
Player1Win == PlayerWin("X")
Player2Win == PlayerWin("O")
=============================================================================
\* Modification History
\* Last modified Tue Nov 03 15:51:31 EST 2020 by ocatenacci
\* Created Mon Nov 02 10:31:22 EST 2020 by ocatenacci
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment