Tic Tac Toe design Case Study

Tic-tac-toe is a pen-and-paper game for two players, O and X, who take turns to mark the spaces in a 3×3 grid. The player who succeeds in placing three of their own marks in a horizontal, vertical or diagonal row wins the game. [wikipedia].

Initial Design Process : An example

Design is going to be a subjective process; as such, there is no right solution, only acceptable solutions. The following process shows you a way to apply design to problems, given your knowledge of Java and object-oriented Design.

Read the problem description and identify Subjects, verbs, and objects. For example, in the sentence:

The Child throws the ball.

The Subject is "Child", the verb is "throws", and the object of the verb is ball. By going to the problem description, you will identify potential classes, instance variables, and methods. You should pay special attention to "has" relationships.

Tic Tac Toe Analysis

Tic-tac-toe is a pen-and-paper game for two players, O and X, who take turns to mark the spaces in a 3×3 grid. The player who succeeds in placing three of their own marks in a horizontal, vertical or diagonal row wins the game.

From this start, we identify the following points:

  1. A Tic-tac-toe game has Player O
  2. A Tic-tac-toe game has Player X
  3. Player O has a mark
  4. Player X has a mark
  5. A Tic-tac-toe game has a Grid
  6. A Grid has nine spaces in a 3x3 arrangement.
  7. Player O and X take turns marking the spaces in the Grid
  8. A Grid is won if horizontal, vertical, or diagonal row contains three of their own marks

Note that the description leaves out some key points

  1. Once the Grid has no more empty spaces, the game is over. So there are three results: Player X wins, Player O wins, or a Draw
  2. Player X goes first
  3. There is only one current Player -- either playerX or playerO.
  4. A player can only place a mark in an empty space
  5. Can a player "give up" and just forfeit the game?
  6. After each player makes his move, the game result is computed. If game is not completed, then players switch turns

Tuesday December 5th

We will work in class to divide this problem description into the relevant classes, attributes, methods.

Make sure you are familiar with the Tic Tac Toe problem game and its description.