CS 1025 Computer Science Fundamentals I
Assignment 4

Department of Computer Science
University of Western Ontario
Given: October 21, 2007
Due: November 11, 2007

This assignment is out of 60 points.

Paper copies of your work must be handed in to the CS 1025 locker (using the assignment submission form) and electronic copies should be submited via the usual Computer Science Department electronic assignment submission system.

Paper copies of your work must be handed in to the CS 1025 locker and electronic copies should be submited via the usual Computer Science Department electronic assignment submission system. Detailed instructions on how to submit an assignment are located on the How to Submit Assignments page.

Please see the course outline for information on late penalties and the rules of ethical conduct.


Introduction

In this assignment you will create a graphical user interface for a Reversi game. A Reversi game-playing engine will be posted once the cut-off for handing in Assignment 3 has passed.

Question 1. GUI Representation (15 points)

Create two classes ReversiGUI_Board and ReversiGUI_Square. The class ReversiGUI_Square should extend the class JButton from Swing, and the class ReversiGUI_Board should extend extend the class JFrame.

The class ReversiGUI_Square should have methods:

that respectively set the square to be empty, contain a white piece, contain a black piece and change the color of the piece on the square (if there is one). For now you don't need to make the buttons respond to mouse events. The squares should represent a white piece with a text label "O", a black piece with a text label "X" and an empty square with a blank label.

The class ReversiGUI_Board should give a nrows x ncols grid of ReversiGUI_Squares. The representation should include

Question 2. Responding to Mouse Events (15 points)

Add a MouseEventListener to ReversiGUI_Square so that clicks on a square cycle through the three possibilities empty square, white piece, black piece. That is, one click changes from empty square to white piece. A second click changes from white piece to black piece. A third click changes from plack piece to empty. A fourth click changes to white piece again, etc.

Question 3. Communication between Squares and the Board (15 points)

Modify the constructor for ReversiGUI_Square so that it takes a ReversiGUI_Board object as a parameter.

Modify the MouseEventListener on the squares so that mouse clicks cause the entire row and entire column of the square (i.e. the cross of all nrows + ncols - 1 squares) cycle through the three possibilities (as in question 2).

Question 4. Properly Record Human Moves (10 points)

Modify ReversiGUI_Board and ReversiGUI_Square to

Question 5. Hook the GUI up to a Game-Playing Engine (5 points)

Modify your program so that after the human player moves, it consults a game-playing engine to find the move that the computer will make. A Reversi game-playing engine will be posted after the cut-off for Assignment 3 has passed (that is, on Monday October 27).

Note that this program orgnization does not allow the computer player to "think" while the human player is thinking. A more advanced game would allow the computer player to explore the game tree as a parallel thread.

Bonus Questions

You do not have to do these, but they might be fun to try. They require ideas not covered in class, but I would be happy to discuss them with you and get you started.

Question 6. Using Images on Buttons (15 Bonus Points)

Modify your program so that it displays pictures instead of text labels on the squares.

Question 7. Generic User Interface (30 Bonus Points)

Modify your program so that there is a Java interface ReversiUI and that the ReversiGUI_Board and a new ReversiTextBoard are now classes with that interface. Modify your game so that it takes a ReversiUI object and plays the game without knowing whether it is using a text or graphical user interface.

Question 8. Thinking in Parallel (30 Bonus Points)

Modify your program so that it explores the tree in parallel with the human player thinking.