Project: Add Three game (final project)

Write a class named AddThreeGame for a two-player game. The players take turns choosing numbers from 1 to 9. A number cannot be chosen if either player has already chosen it. If any three of a player's numbers add up to 15, that player wins. If all nine numbers are chosen and nobody has won, the game is a draw.

The class needs private data members for:

  1. which numbers have been chosen, and by whom
  2. the current state, which is one of "FIRST_WON", "SECOND_WON", "DRAW" or "UNFINISHED"
  3. whose turn it is

The class must have these methods:

Here is how the class could be used:

game = AddThreeGame()
game.make_move("first", 2)
game.make_move("second", 5)
result = game.make_move("first", 7)
state = game.get_current_state()

Save the file as AddThreeGame.py.

Show a solution

Try the project on your own first. This is one working solution, followed by its tests. Press Run to run the tests. Read them to see what thorough testing looks like, then change the solution and run again to watch a test fail. The testing tools used here (classes and unittest) are not part of the course yet, so do not worry about how they work.

Projects run on your own computer, so you tell us when you are done.