Express Tic Tac Toe in set theory notation?

423 Views Asked by At

I would like to express the statement "All perfect plays in Tic Tac Toe lead to a draw". But using set theory notation. (And then generalise this to larger grids).

Let $Cell$ be the set of cells.

I would describe a win for X as:

$$win(Cell,X) = \exists_n :(\forall_m:Cell_{n,m}=X \lor \forall_m: Cell_{m,n}=X) \lor \forall_n: Cell_{n,n}=X \lor \forall_n :Cell_{n,4-n}=X$$

Perhaps I could create a propositional function $P(n)$ which is true if Tic Tac Toe is winnable for the first player in perfect play for an n by n grid. Not sure how to express moves in a game though. Perhaps by some recurssion.

I'm thinking if $S$ represents the state of a game. Then the function $nextMoves(S)$ would give the set of next possible states.

Maybe do a recursive formula on a state $S$ which belongs to the states when it is X's turn:

$$winnable(C,X) = win(C,X) \lor \exists_{x\in nextMoves(C)}: \forall_{y\in nextMove(x)}:winnable(y,X)$$

Which translates as either S is a winning state or there is a move for X such that every move O makes the state is still winnable by X.

1

There are 1 best solutions below

2
On BEST ANSWER

Ok, this takes a lot of building up of things to work with, so bear with me while I develop a bit of game theory using set theoretic notions. Here we assume that noughts always have the first move.

I'll leave it to you to translate everything to first-order formulas, unless, of course, you consider it a bit of a waste of time.


Let's first define what the board looks like: let $B={\{e,x,o\}^9}$ be the set of functions from $\{1,2,3,4,5,6,7,8,9\}$ to $\{e,o,x\}$ ($e$ for empty, $o$ for nought, $x$ for cross). We see these maps as representations for a position. You could see for example the function $f$ given by $1,2,5\mapsto e$; $4,6,8\mapsto o$; $3,7,9\mapsto x$ as representing the position: \begin{align} \begin{array}{l|l|l} 1&2&3\\\hline 4&5&6\\\hline 7&8&9 \end{array}\mapsto \begin{array}{l|l|l} &&x\\\hline o&&o\\\hline x&o&x \end{array} \end{align}

Next, given a position, we need to determine which positions are legal moves. This depends on which player has his turn, so let's call our players $O$livia (playing noughts) and $X$avier (playing crosses). The legal moves can then be formulated as a map $v:B\times\{O,X\}\to\mathcal P(B)$ that maps a board position and a player to a set of board positions (representing the move of said player).

For example $v(f,O)$ with $f$ as above would map to the set of board positions (i.e. functions in $B$) corresponding to the following diagrams:

\begin{align} \begin{array}{l|l|l} o&&x\\\hline o&&o\\\hline x&o&x \end{array}; \begin{array}{l|l|l} &o&x\\\hline o&&o\\\hline x&o&x \end{array}; \begin{array}{l|l|l} &&x\\\hline o&o&o\\\hline x&o&x \end{array} \end{align}

Note that if we let $f'$ be the last diagram on the right, then $v(f',X)=\varnothing$, since there are no legal moves (since Olivia has won, so the game is finished).

Now, we determine what a partial match is: it is a finite sequence $m\in B^{<\omega}$ of positions $m=\langle f_0,\dots,f_n\rangle$ such that $f_0$ is the function $f_0:n\mapsto e$ for all $1\leq n\leq 9$ and for each even $i$ we have $f_{i+1}\in v(f_i,O)$, and each odd $i$ we have $f_{i+1}\in v(f_i,X)$. That is, we start the sequence with the empty position, then each even position is followed by a legal move by Olivia, and each odd position is followed by a legal move by Xavier.

A complete match is defined as any partial match $m$ in which there is no partial match that extends $m$ with another move (i.e. there are no legal moves from the last position for the player whose turn it is). Let's denote the set of partial matches by $\mathrm{PM}$, the set of partial matches that are not complete by $\overline{\mathrm{PM}}$, the set of complete matches by $\mathrm{CM}$, the set of incomplete partial matches of odd length by $\overline{\mathrm{PM}}_O$ (for it being Olivia's turn) and the set of incomplete partial matches with even length by $\overline{\mathrm{PM}}_X$.

Now we have to define what the winning condition is: we define subsets $B_X,B_O\subset B$ as the winning positions for Xavier and Olivia respectively. For example, we can define $B_X$ as: \begin{align} f\in B_X\iff f[\{1,4,7\}]=\{x\}\lor f[\{2,5,8\}]=\{x\}\lor\dots \end{align} where $f[s]$ denotes the range of $f$ over the set $s$. We then define a complete match to be won by Xavier if the last position of the match is in $B_X$, to be won by Olivia if the last position is in $B_O$ and otherwise to be drawn. This can be represented as a function $CM\to\{O,X,D\}$, matching complete matches with the winning player / draw.

Before we can define what a perfect play is, we need to know what a strategy is: a strategy for, let's say, Olivia is a map $S_O:\overline{\mathrm{PM}}_O\to B$ such that a partial match $\langle f_0,\dots,f_n\rangle$ is mapped to a position $b\in v(f_n,O)$. So a strategy maps any partial match in which it is Olivia's turn (and the match isn't completed yet) to a legal move.

A complete match $\langle f_0,\dots,f_n\rangle$ is in accordance with a strategy $S_O$ if every partial match $\langle f_0,\dots,f_k\rangle$ with $k<n$ in which it is Olivia's turn has $f_{k+1}=S_O(\langle f_0,\dots,f_k\rangle)$.

Now a winning strategy for Olivia from a partial match $m$ is a strategy $S_O$ such that for any strategy $S_X$ of Xavier, the complete matches that extend $m$ in such a way that all partial matches of the complete match are in accordance with both $S_O$ and $S_X$ are all won by Olivia.

Of course all of the above can be done with Olivia and Xavier's roles swapped.

Now we can formulate "All perfect plays in Tic Tac Toe lead to a draw" by the statement that there exists no winning strategy for Olivia nor for Xavier starting at the partial match $\langle f_0\rangle$.


Some remarks:

  • We could have worked with a subset of $B$, since not every board position can be reached during a game (e.g. a board filled with crosses)
  • We could have defined the legal move map as a function $v:B\to \mathcal P(B)$ and infer whose turn it is based on the number of noughts and crosses on the board
  • The two sets of winning positions $B_X$ and $B_O$ could have nonempty intersection, meaning that we need to make sure that a complete match cannot end at such a position. This is however not a problem, since there are no legal moves for a winning position, and it is impossible to find a legal move that goes from a non-winning position for both players to a winning position for both players.