HOMEWORK ASSIGNMENT #2
Assigned Date: Wednesday, September 15, 2004
Unit Tests and Javadoc Due: Friday, September 24, 2004
Complete Project Due: Friday, October 1, 2004
Due Time: Noon
Updated: Monday, September
20, 2004, 4:45 PM
Monday, September 27, 2004, 8:45 AM
Monday, September 27, 2004, 3:00 PM
Wednesday, September 29, 2004, 3:35 PM
This assignment focuses on Object-Oriented Design, functional cohesion, and unit testing. It will also give you an opportunity to get comfortable with BlueJ’s javadoc and unit testing features.
See previous assignment.
Develop a set of Java classes that implement a game of Tic-Tac-Toe. In our version of the game, the two players, human and computer, play in turns, placing X's and O's, respectively, on the 3x3 square board. The human player always goes first. The game goes on until there is either a winner (3 X's or 3 O's in a vertical, horizontal, or diagonal line), or the game is a draw (all squares are occupied and no one has won).
The program should display the current board configuration after each move, e.g.,
X | |
O | |
X | O |
and prompt the user to enter a move (a number from 1 to 9). The human player always goes first. Squares are numbered consecutively, from 1 to 9, where 2 is the middle square on the top row. The program should be as robust as possible. When the game is over it should output a message describing the outcome.
To implement the Computer player, you may use AIPlayer.class. This file encapsulates the Artificial Intelligence algorithm for determining the computer move. For example,
AIPlayer player = new AIPlayer(); // creates a computer player of perfect ability
AIPlayer player = new AIPlayer(1.0); // creates a computer player of perfect ability
The constructor’s ability parameter may range from 0.0 (novice) to 1.0 (expert). (Note: Actually, values outside this range are OK, however anything less than 0.0 is treated as 0.0 (how novice can you be?) and anything greater than 1.0 is treated as 1.0 (you cannot improve perfection!)).
To get player to calculate a move for you, do:
player.getMove(board); // get computer move
This is a void method, which updates its Board argument with the player’s move (player always plays ‘O’). It outputs informational messages to System.err.
Note: AIPlayer is not in the public domain. It is made available under a Creative Commons License.
Your program should be implemented using BlueJ. Create a project called, what else, TicTacToe. In that project have, minimally, the following classes, with the specified method signatures:
For each of these classes, create a BlueJ unit test class (except the system driver, TicTacToe). For example, for class Board, create a test class TestBoard which thoroughly tests Board’s methods.
Hint: Create the test classes first. To do so, implement all above methods as stubs first, then create the test classes, then implement and test each of the above methods.
You should submit your source file on a floppy disk, as per syllabus instructions.
Source filenames to be submitted:
A zip archive named <firstName_lastName_fourLastDigitsofSSN>.hmwk2.zip (for example, Bill_Manaris_2308.hmwk2.zip). This archive should contain the following files:
· TicTacToe (the BlueJ project directory). Within TicTacToe there should be the following files:
o Readme.txt (see Widget for a sample)
o Any files generated automatically by BlueJ (e.g., bluej.pkg, bluej.pkh, etc.)
o Game.java, Player.java, Human.java, Computer.java, Board.java, Square.java, TicTacToe.java.
o A doc subdirectory with the Javadoc API documentation generated by BlueJ, for each of the classes above.
o Unit test classes for each class above.
o Any other auxiliary classes needed (e.g., BearcatScanner.jar). In other words, I should be able to unzip your submission and run it without modifications or additions.