Write a tic-tac-toe game, but with a twist. Rather than the standard 3x3 board, this one is played on a 4x4 board.
Don't worry, you don't need to write the part that decides the computer's move. Instead, your program just needs to arbitrate between 2 human players. Specifically, your program should check if each of the user's moves are valid, and whether the game is won by the first player (X), the second player (O), or tied. X always goes first.
Here is the layout of the 4x4 board:
+-----+-----+-----+-----+ | 1,1 | 1,2 | 1,3 | 1,4 | +-----+-----+-----+-----+ | 2,1 | 2,2 | 2,3 | 2,4 | +-----+-----+-----+-----+ | 3,1 | 3,2 | 3,3 | 3,4 | +-----+-----+-----+-----+ | 4,1 | 4,2 | 4,3 | 4,4 | +-----+-----+-----+-----+
Rules of the game is similar to standard game.
That is, players alternate moves.
The first player puts down an X by specifying
a
The player who first puts down three consecutive pieces,
either in a row, column, or diagonally, wins the game.
The game ends in a tie if neither player can win the game.
In this case, your program should print:
GAME TIED.
Here is a sample run to illustrate the requirement:
The text in bold are user inputs.
EXTRA CREDIT.
There are a few ways to earn extra credit for this program.
The first way is to make your program more general so that
it is not limited to a 4x4 board, but works on arbitrary shapes,
yet the same rules for winning applies.
For example, the tic-tac-toe board may look like:
Another way to earn extra credit requires that you read
ahead on applets, and improve the interface to the program.
Rather than having the users type in coordinates,
the X and O pieces can be specified by simply clicking
on a graphical display of the board.
Yet another way to earn extra credit
(for the really adventurous ones) is
to allow the user to play against the computer.
Your program would have to generate the moves of the computer player,
and they better be good :-) and not just random moves.
Important requirement: name your
Remember to compile and test your program to make sure things compile
and execute correctly on the unix.ic machines.
Log into unix.ic.ucsc.edu and submit the source code
(i.e. TicTacToe.java) using the command:
Each partner should separately submit a
log file
for each programming assignment.
Welcome to the 4x4 Tic-Tac-Toe game:
+-+-+-+-+
| | | | |
+-+-+-+-+
| | | | |
+-+-+-+-+
| | | | |
+-+-+-+-+
| | | | |
+-+-+-+-+
Player 1: 1,1
+-+-+-+-+
|X| | | |
+-+-+-+-+
| | | | |
+-+-+-+-+
| | | | |
+-+-+-+-+
| | | | |
+-+-+-+-+
Player 2: 2,1
+-+-+-+-+
|X| | | |
+-+-+-+-+
|O| | | |
+-+-+-+-+
| | | | |
+-+-+-+-+
| | | | |
+-+-+-+-+
Player 1: 2,2
+-+-+-+-+
|X| | | |
+-+-+-+-+
|O|X| | |
+-+-+-+-+
| | | | |
+-+-+-+-+
| | | | |
+-+-+-+-+
Player 2: 3,1
+-+-+-+-+
|X| | | |
+-+-+-+-+
|O|X| | |
+-+-+-+-+
|O| | | |
+-+-+-+-+
| | | | |
+-+-+-+-+
Player 1: 3,3
+-+-+-+-+
|X| | | |
+-+-+-+-+
|O|X| | |
+-+-+-+-+
|O| |X| |
+-+-+-+-+
| | | | |
+-+-+-+-+
PLAYER 1 WINS!
+-+-+-+-+-+-+-+-+
| | | | | | | | |
+-+-+-+-+-+-+-+-+
| | | | |
+-+-+-+-+
| | | | |
+-+-+-+-+-+-+-+-+
| | | | | | | | |
+-+-+-+-+-+-+-+-+
| | | | | | | | |
+-+-+-+-+-+-+-+-+
| | | | | |
+-+-+ +-+-+
| | | | | |
+-+-+ +-+-+
| | | | | |
+-+-+-+-+-+-+-+-+
| | | | | | | | |
+-+-+-+-+-+-+-+-+
| | | | | | | |
+-+-+-+-+-+-+-+
This will greatly help us speed up the grading of your programs.
submit cmps012a-ap.f03 prog4 TicTacToe.java
You can submit more than once, for example to update your
previous submission with new/improved code.
However,
each pair should designate 1 account to be used for doing
submissions.
Refer to the programming guide link for specifics on requirements and grading guide.