Preparing your design workspace

Loading the problem and your saved attempt…

Design a Tic-Tac-Toe Game

Model a two-player tic-tac-toe game on an n x n board: turns, moves, refused moves, wins and draws.

For this exercise, assume two people play tic-tac-toe on one computer by taking turns. A game is created with a board size n between 3 and 10 (the classic game uses 3). Player X always moves first, and then the turn passes back and forth between X and O.

A move gives the player making it (X or O), a row, and a column, with rows and columns counted from 0. A player wins as soon as they fill a whole row, a whole column, or one of the two diagonals with their mark; if every cell is filled and nobody has won, the game is a draw.

A move is refused, with a clear reason and no change to the game, when the game has already ended, it is the other player's turn, the cell is outside the board, or the cell already holds a mark. After each accepted move the game reports whether it is still going, who won, or that it is a draw.

Players can also ask whose turn it is, read the board, and start a new game. Design the objects, their responsibilities, the interfaces, and the interactions. No code is needed. One follow-up asks you to report a win without scanning the board.

A computer opponent, playing over a network, saving games, undo, and drawing the board on screen are out of scope. Everything runs on one thread.