\documentclass{article}
\usepackage{fullpage}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
\section*{Determining Legal Moves for \texttt{O} in Reversi}
\subsection*{Problem Statement}
In Reversi, players \texttt{X} and \texttt{O} take turns placing tiles on empty squares on the board. A move is legal if, by placing a tile on an empty square, it brackets one or more of the opponent's tiles between the newly placed tile and another of the player's tiles in a straight line (horizontal, vertical, or diagonal). All bracketed opponent tiles are then flipped to the player's own color.
Given the following Reversi board position (an 8x8 board):
[
\begin{tabular}{|c|c|c|c|c|c|c|c|}
\hline
. & . & . & . & . & . & . & . \
\hline
. & . & . & . & . & . & . & . \
\hline
. & . & . & . & . & . & . & . \
\hline
. & . & . & \texttt{O} & \texttt{X} & . & . & . \
\hline
. & . & . & \texttt{X} & \texttt{O} & . & . & . \
\hline
. & . & . & . & . & . & . & . \
\hline
. & . & . & . & . & . & . & . \
\hline
. & . & . & . & . & . & . & . \
\hline
\end{tabular}
]
Assuming it's \texttt{O}'s turn (since \texttt{X} moves first and the board has an odd number of tiles), our goal is to determine all possible legal moves for \texttt{O} and display the board with each possible legal move replaced by an exclamation mark \texttt{!}.
\subsection*{Reversi Rules for Legal Moves}
A move by player \texttt{O} is legal if:
\begin{enumerate}
\item The square is empty.
\item In at least one direction (horizontal, vertical, or diagonal), there is a straight line of one or more \texttt{X} tiles immediately adjacent to the square, ending with an \texttt{O} tile. There must be no empty squares or other \texttt{O} tiles interrupting this line.
\end{enumerate}
\subsection*{Step-by-Step Solution}
Let's analyze each empty square on the board and determine if it constitutes a legal move for \texttt{O}. We'll proceed systematically, row by row, from top-left to bottom-right.
\textbf{Note:} For brevity, we'll only consider empty squares adjacent to at least one \texttt{X}, as other squares cannot be legal moves.
\subsubsection*{Analyzing Potential Moves}
Let us denote the board positions using coordinates (r,c), where r is the row number (from 1 to 8, top to bottom) and c is the column number (from 1 to 8, left to right).
\begin{itemize}
\item \textbf{Square (3,5)}: This square is above an \texttt{X} at (4,5). Checking in the southward direction:
\begin{itemize}
\item (4,5) is \texttt{X}
\item (5 is \texttt{O}
\end{itemize}
Since we have an \texttt{X} followed by an \texttt{O}, this is a legal move for \texttt{O}.
\item \textbf{Square }: This square is right of an \texttt{X} at . Checking in the westward direction:
\begin{itemize}
\item is \texttt{X}
\item is \texttt{O}
\end{itemize}
Since we have an \texttt{X} followed by an \texttt{O}, this is a legal move for \texttt{O}.
\item \textbf{Square }: This square is left of an \texttt{X} at . Checking in the eastward direction:
\begin{itemize}
\item is \texttt{X}
\item is \texttt{O}
\end{itemize}
Since we have an \texttt{X} followed by an \texttt{O}, this is a legal move for \texttt{O}.
\item \textbf{Square }: This square is below an \texttt{X} at . Checking in the northward direction:
\begin{itemize}
\item is \texttt{X}
\item is \texttt{O}
\end{itemize}
Since we have an \texttt{X} followed by an \texttt{O}, this is a legal move for \texttt{O}.
\item \textbf{Square }: This square is diagonally adjacent (northwest) to an \texttt{X} at . Checking in the southeast diagonal:
\begin{itemize}
\item is \texttt{O}
\item Move invalid since immediate tile is \texttt{O}.
\end{itemize}
The immediate adjacent tile is \texttt{O}, so this is not a legal move.
\item \textbf{Square }: Similar reasoning shows this square is not a legal move.
\item \textbf{Square }: Checking southeast diagonal:
\begin{itemize}
\item is \texttt{X}
\item is \texttt{X}
\item is empty
\end{itemize}
The line does not end with an \texttt{O}, so not a legal move.
\end{itemize}
After analyzing all relevant squares, we find that the legal moves for \texttt{O} are at positions:
[
(3,5),\ (4,6),\ (5,3),\ (6,4)
]
\subsection*{Outputting the Board with Legal Moves}
We will display the board, replacing each legal move square with an exclamation mark \texttt{!}.
[
\begin{tabular}{|c|c|c|c|c|c|c|c|}
\hline
. & . & . & . & . & . & . & . \
\hline
. & . & . & . & . & . & . & . \
\hline
. & . & . & . & \texttt{!} & . & . & . \
\hline
. & . & . & \texttt{O} & \texttt{X} & \texttt{!} & . & . \
\hline
. & . & \texttt{!} & \texttt{X} & \texttt{O} & . & . & . \
\hline
. & . & . & \texttt{!} & . & . & . & . \
\hline
. & . & . & . & . & . & . & . \
\hline
. & . & . & . & . & . & . & . \
\hline
\end{tabular}
]
\subsection*{Additional Notes}
Each \texttt{!} indicates a legal move for \texttt{O}. Upon choosing any of these moves, \texttt{O} would capture the bracketed \texttt{X} tiles according to the game rules.
\end{document}