Programming
Assignment 5
Due March 24, before
9:30am |
||
Program Description |
||
In
this assignment, you will develop your own player methods for the game
of tic-tac-toe.
A human can play against your program by clicking the mouse to place an
X on the tic-tac-toe
board. Your method would then select the next move for the
computer to place an O.
The human always goes first. Your player methods should be
good enough so that the human never wins; instead, the game should end
in a "draw" or "the computer wins." |
||
What You Do
|
||
It is assumed that
you are using NetBeans to develop your code for this assignment. Create a new NetBeans project that is a
"General" "Java Application". Name your
NetBeans project program5. Download the source for the Main.java, TicTacToe.java and MyPlayer.java classes, and store these in the program5/src/program5 directory. Using NetBeans, you are to implement two methods for the class MyPlayer:
This
method searches the tic-tac-toe board to see if there is a winning move
available for player. In
other words, the method looks for a row, column, or diagonal on the
current board where there is an open spot, and the other two spots are
already taken by player. The
board is a 3x3 array. This method returns an array {row,column}
of the winning move for player if
there is one. If there is no winning move, then the method
returns {-1,-1}.
This
method selects the next move for player
for the given 3x3 board.
It returns a 1-D array that gives the {row,column} location selected
for the next move. If there is no empty spot, then the method returns
{-1,-1}.
Here is one possible strategy for selecting the next move:
ConstantsThe board is represented as a 3x3 array. Each spot on the board can have one of three possible values. These values are static constants defined in the class TicTacToe.
Programming
Style
You are expected to
follow the CS111
/ CS112 Java Coding Standard. You will be graded on
programming style. Each
student must schedule two meetings with course staff to review a
submitted program's style. Two lab times will be set aside
for this (refer to course schedule). You can also arrange to have
tutors review your program style during scheduled tutoring
hours. This is meant to allow students to get guidance and
feedback on style, and the grading of style is separate from the
grading of Program Assignment 5. |
||
What You Submit
|
||
Submit
your file called MyPlayer.java
in a directory named 05
via gsubmit
. Under no circumstances will late assignments be accepted. |
||
Grading Criteria
|
||
20%
Submitted code
compiles without errors 20% findWinningMove returns the correct value for the cases given in Main.java 20% findWinningMove returns the correct value for other cases given at testing time. 20% selectMove returns the correct value for the cases given in Main.java 20% selectMove does not lose in games played against an automated test player given at grading time. |
||