CS 1713 Introduction to Computer Science: Spring 2012


This is an in-class activity for Graphics Case Study 8: Tic Tac Toe.

Get a copy of the Tic Tac Toe project we did in class on Thursday, April 19.

You can find a copy on the Y drive at Y:/zips/gcs08-2012-04-19.zip or you can download it here.

You will complete the project in stages.

The class will be divided into groups.
After finishing the implementation of a method, you will help other members of your group with their implementation.
Only when all members of the group have finished a particular stage, should you go on to the next stage.

If you get stuck, ask for help from a member of your group or from the instructor.

As you finish a method, indicate your progress on ClassQue.

Here are the stages that you will use for Part 1:

  1. Get a copy of the starting point.
    You can download a new copy or use the one from class.
    This copy has a simple working GuiPlayer which plays against a computer.
    The computer alwasy makes the first available move, so it should be easy to win.
    Make sure this is working before going on to the next stage.
  2. Modify the TicTacToe class so that it uses two GuiPlayers (no DumbComputerPlayer).
    To play this, you will need to move one of the boards aside since they appear one on top of the other.
  3. Modify GuiPlayer so that the O-Player board appears in a different place on the screen.
    You can do this as follows:
    1. In setId, if the id is O_CHAR, execute
      frame.setLocation(300,0);
    2. You will have to make the frame an attribute, rather than a local variable of the constructor.
    3. also execute:
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    4. If you want to be more fancy, you can move the o-player to be next to the other board, and have only the x-player set the default close operation.
  4. Have the move method of Game check for the correct player and use an appropriate inform to notify of a problem.
  5. Have the move method of Game check for valid row and column values and that the slot is empty.
  6. Have the move method use appropriate inform calls when the game is over.
  7. Have the move method not allow a move if the game is over.
  8. Modify the GuiPlayer so that it indicates whether it is X or O.
  9. Modify the GuiPlayer so that it displays inform messages.
If you finish all of these, you can work on your own on Part 2:
  1. Use the ComputerPlayer in place of one of the GuiPlayers.
  2. Modify the ComputerPlayer so that it make a random valid move.
  3. Modify the ComputerPlayer so that if it is making the first or second move it tries to move in the center. Otherwise on this move it tries to move in the upper left corner.
  4. Modify the ComputerPlayer to make a winning move it one is available.
  5. Modify the ComputerPlayer to make a blocking move is there is no winning move and one is available.
  6. Modify the ComputerPlayer to attempt to make a move which will give it 2 ways to win, if the other choices are not available.
  7. Is this good enough to guarantee that the computer will never lose (for 3x3).
  8. Write your own gameOver method.