Outlab 5: Tic-Tac-Toe

Due: Monday 31 Jul at 10 pm


Practice everything we have learned this semester, to include 2-d arrays.


This is a lab that allows you to work with 1 partner. A group of two is the maximum.

Problem Statement

You will build an application that allows a person to play tic-tac-toe against the computer. Your application will print out the board, ask the user to select a spot, update the spot selected, and make a move on its own. This will continue until the game ends (3 sequential spots having the same mark in the same row, column, diagonal, or if no more moves are possible due to the lack of vacant spots). Your application will also do limited error checking to ensure occupied spots won't be overwritten with new values.



  1. You won't be able to give this lab a good honest effort until we talk about multi-dimensional arrays on July 20th. Before then you can still map out how you expect objects to interact.
  2. This is a hard lab and will take many hours. It is worth 10% of your total class grade. Take it seriously. It WILL take you a lot of time. My solution has close to 300 lines of code.
  3. You will probably jump back and forth between the two classes, but to get you started, kick things off with the Board class. Think you need something in the Board class to represent the actual board? The point of the constructor is to give things an initial condition. Can you think of a good default initial condition for a tic-tac-toe board? What should the spots be filled with? Do you mean literally nothing (null), or do you mean an empty space (" ")?
  4. After you make the Board constructor (and maybe an instance variable...), work on the print method. It will be hard and will take you some time, but will be good practice dealing with 2-d arrays in preparation for the rest of the assignment.
  5. After you have a 2-d array working and printing, think about the rest of the assignment. In English, what do you need to check to see if the game is over? I check four different things (1 - Do the rows have a winner? 2 - Do the columns have a winner? ...). Perhaps each thing you check, should be its own method.
  6. Start with plain English when building your methods: How should the move methods operate? Generate (randomly or through input) row and column values. If that spot is empty, place the mark. If not...
  7. My Player class has only two non-constructor methods, and they are both called from the Driver. My Board class has nine non-constructor methods and some are only called from insde the Board class, some are called from the Driver, and some are called from the Player class. It is important to be organized when building this program.
  8. Think about some lessons from previous labs. Which class should be responsible for reading input when the human wants to make a move? Which class should be responsible for changing the board? Perhaps I need a method in the board class that will enable Players to check whether or not a space is vacant, or maybe another method that will enable a Player to add a mark to the board.

Bonus Point

Make the computer player smarter. Don't make it randomly select a spot, but give it some strategy. If you do this, upload a text document with your submission explaining the strategy you implemented. You can also think of your own extension, but if you do, you may want to convince the instructor that it is complicated (or feasible) enough.


By Monday 31 Jul. at 10:00 pm, submit the files Player.java and Board.java into the appropriate D2L dropbox folder. DO NOT SUBMIT .class files!

Grading - 20 points