This assignment is worth 20% of the marks for the unit, corresponding to 20 hours of work. Deadline for submission of zipped BlueJ project file by email is Monday 30th April. Late submission will be penalised as follows: 1 day late 10% penalty; 1-2 days late 20% penalty, 2-3 days late 50% penalty.
Warning on Plagiarism
It is easy to find implementations of this game on the web. However, copied solutions will not be accepted and you will receive zero for the entire unit if any part of your solution has been directly copied.
Aims and Descriptions
The aim of the assignment is to develop, using BlueJ, a class TicTacToe which
plays the game tic-tac-toe. You can see an implementation of this game here. The game will be played with a command-line
interface which accepts different user commands.
- A first version of the program will simply allow the user make moves for
both players, recording and displaying the state of the game. (6 marks)
- A second version will include methods to automate one of the players and decide which move to make next.(7 Marks)
- A third version of the program will remember the name of each user and display statistics on the perfomance of different players. (7 marks)
I suggest that to begin with version 1, you create two classes
- TicTacToe itself, the class which contains the main method which controls how the session will run.
TicTacToe will initialise the board and then enter into a command loop
which issues a prompt, accepts a command from the user, causes the command to be executed and then waits for the next command. A minimal set of commands would be
N.B. You may give these commands parameters as you like. So, for example, you might have "w X" to mean "is a winning position for player X. Note also that it is the job of the command interpreter to call the appropriate Board methods.
Versions 2 and 3 can be immplemented by adding further commands. You may find the need to introduce further classes. These design choices are up to you.
- q (quit): exit the program
- s (show): display the board
- p (put): put a character in a given square
- w (winning): the current board position is a winning position for whoever made the last move
- Board, which contains the methods for actually playing the game. This should include methods such as
- public void clearBoard( )
- public void put(char, int x, y)
- public void display ( )
- public void isWinning ( )
You may if you wish make use of a magic square to determine whether a given board situation is a win or a lose. The basic property of a magic square is that a straight line of three squares always adds up to the same number. The following is an example: