I started with the inner board logic since it's basically just regular TTT, but the nesting tripped me up more than I'd like to admit.
Start by defining a clear data model: represent the board as a 3x3 array of sub-boards, each a 3x3 array of cells, and track the active sub-board constraint. Then explain incremental win detection: for each move, check only the affected row, column, and diagonal in the sub-board, and if a sub-board is won, check the corresponding lines in the outer grid. Emphasize efficiency and correctness, and discuss handling of edge cases like forced moves and draws.
Pro tip: Mention that you can precompute win lines (8 per board) and use bitboards for O(1) win checks, but keep the explanation accessible. Also, note that the active sub-board constraint can be enforced by tracking the last move's cell coordinates.
Choose a representation: a 3x3 array of sub-boards, each a 3x3 array of cells (or a flat 9x9 array with index mapping). Track the active sub-board and the overall winner.
Given a move (sub-board coords, cell coords, player), validate it against the active sub-board constraint and cell emptiness. Update the cell and determine the next active sub-board (the cell's coordinates).
After placing a mark, check only the row, column, and diagonals passing through that cell within the sub-board. If a win is found, mark the sub-board as claimed by the player.
When a sub-board is claimed, check the corresponding row, column, and diagonals in the outer grid. If three claimed sub-boards align, declare the overall winner.
Address draws, forced moves when the target sub-board is already won, and potential optimizations like bitboards or precomputed win lines.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.