4

I am currently writing my thesis and need to include figures of tic-tac-toe/noughts and crosses games. Up until now I created my figures using PowerPoint (see image 1, and 2).

I looked up similar questions and found the following ones:

  1. Beamer: Noughts and crosses
  2. How to represent tic tac toe table in Latex?

However they either use a table to represent the game or macros to place an X or O character on a board. Since I also need dashed symbols (see image 5) to represent optimal moves I can not use their approach.So the individual slots of the board are either blank, contain their index or a symbol. Furthermore I would like to place either a single line of text beneath the diagram or multiple lines to its right.

Could anybody point me to other questions or resources that I could use to create the figure below?

game of tic-tac-toe with zero-based index and text underneath game of tic-tac-toe with zero-based index and text underneath

game of tic-tac-toe with empty slots and text on the right game of tic-tac-toe with empty slots and text on the right

game of tic-tac-toe optimal moves highlighted by dashed symbol

game of tic-tac-toe optimal moves highlighted by dashed symbol

legnib
  • 77

1 Answers1

5

EDIT

I thought it would be more interesting to just throw a matrix of what you wanted into the cells and get the result, so here is an improved version:

\documentclass{article}
\usepackage{tikz}

\newcounter{num} \newcommand{\tictactoe}[1] { \begin{tikzpicture}[line width=2pt] \def\r{3mm} \tikzset{ circ/.pic={\draw circle (\r);}, cross/.pic={\draw (-\r,-\r) -- (\r,\r) (-\r,\r) -- (\r,-\r);}, opt/.pic={\draw[opacity=0.2] (-\r,-\r) -- (\r,\r) (-\r,\r) -- (\r,-\r);} }

        % The grid
        \foreach \i in {1,2} \draw (\i,0) -- (\i,3) (0,\i) -- (3,\i);

        % Numbering the cells
        \setcounter{num}{0}
        \foreach \y in {0,...,2}
            \foreach \x in {0,...,2}
                {
                \coordinate (\thenum) at (\x+0.5,2-\y+0.5);
                %\node[opacity=0.5] at (\thenum) {\sffamily\thenum}; % Uncomment to see numbers in the cells
                \addtocounter{num}{1}
                }


    \def\X{X} \def\x{x} \def\O{O} \def\n{n}

    \foreach \l [count = \i from 0] in {#1}
        {
        \if\l\X \path (\i) pic{cross};
        \else
            \if\l\O \path (\i) pic{circ};
            \else
                \if\l\x \path (\i) pic{opt};
                \else
                    \if\l\n \node[opacity=0.5] at (\i) {\sffamily\i};
                    \fi
                \fi
            \fi
        \fi
        }
\end{tikzpicture}
}


\begin{document}

\tictactoe{O,x,n,
           x,X,x,
           n,x,O}

\vspace*{1cm}

\tictactoe{ ,O,X,
           O,X, ,
           X, ,O}           

\end{document}

TicTacToe

another one

SebGlav
  • 19,186