CS 340 - Assignment 3

Dots and Boxes Game

Due: Thursday 10/13/2005

The game of Dots and Boxes is played on a grid with rows and columns of dots as shown here:

The actual number of rows and columns on the grid does not matter.

On a turn, a player connect two two adjacent dots together with either a horizontal or vertical line (diagonal lines are not allowed). If the player completes a box by drawing the fourth side of the box, that box belongs to the player and the player get to take another turn. The player who completed the most boxes once all dots have been connected is the winner.

Rules to the game can be found at http://www.drking.plus.com/hexagons/dots/. While a step by step example of the game with a discussion on strategy can be found at http://mathworld.wolfram.com/DotsandBoxes.html. A version of this game can be found at http://www.well.com/user/argv/java/dots.html or at http://search.teach-nology.com/web_tools/games/dots/. The Mathematical Theory of Dots and Boxes can be found at http://cf.geocities.com/ilanpi/math.html.

This assignment is to create a game using the Java swing GUI libraries. Your game is to track the mouse movements of the user. When the mouse is between two dots, your program is to draw a temporary line between two dots. When the user click the left mouse button, a temporary line will become the line chosen for the user player's move.

Your program is to be "generous" when determining if the mouse is between two dots. The temporary line should appear when the mouse is both above and below a horizontal line and when the mouse is to the left and the right of a vertical line.

The drawing of the dots and the lines is expected to be done using the methods in the Java Graphics class. If you are planning on using some other method, you must get approval from the instructor.

The computer player is to follow a very simple AI algorithm to determine which side should be selected.

  1. If the fourth side of a box can be selected, select such a side. If multiple fourth sides exist, randomly select one of them.
  2. If no fourth side exists and a first or second side of a box can be selected, select such a side. If multiple first or second sides exist, randomly select one of them.
  3. If only the only choice is selecting the third side of a box, select such a side. If multiple third sides exist, randomly select one of them.

When a box is completed, the box is to be marked as whether the user player or the computer player completed the box.

Your program is to have at least 6 rows and column of dots. You are more than welcome to include more rows and columns. For an additional 5 points extra credit, you can allow the user to select the number of rows and columns to be used.

Your solution must contain a line class and a box class to keep track of the information for the lines and boxes in the program.

Your program must also be able to handle a resizing of the screen. When this occurs, the lines are to stretch or shrink to fill up the screen. You may impose a minimum screen size for this program.

In addition to the playing area, your program is to display the number of boxes formed by the computer player and the user player. This information is expected to be displayed using Java Swing components. Your program is also to use a Menu that will allow the user to

Programming Style Grading Criteria

The programming style grade is worth 1% of the final grade for each assignment. Thus the functionality of each assignment is only worth 4% of the final grade. The programming style grade will have a maximum score of 45 and will be graded based on the following criteria.

5 Title page short header: The front page of your program must have a header with your name, course, TA, data, system, and a short description of the program, such as:
     /** ---------------------------------------------------------
     * This program implements a calculator that does addition subtraction,
     * multiplication, and division.
     * Class: CS 340, Spring 2005
     * System: NetBeans IDE, jsdk 1.4.2, Windows XP
     * @author Dale Reed
     * @version January 16, 2004
10 Title page(s) complete description: Following the above short header, you should give a detailed description of what this program does (2 paragraphs minimum). This should be followed by an intuitive description of how you implement your solution, including a description of principal data structures and modules or sections of code. Any extra credit work should be explicitly documented. This section should also include directions on the compilation and execution of your program.

This should include a section called Status: Elements of the assignment that do not work should be well documented here. If some assigned element of your program does not work and you fail to document this, you could lose double the points for this than you would have otherwise.

You may wish to write all this information into a separate README file. This should be done especially when the program has multiple source code files.

5 Meaningful Identifier Names: Identifier names should indicate their purpose. Names should be words separated using capitalization, such as gradesSum. Short loops of ~ 5 lines can use loop counter variables such as i or j.
10 Comments. Every function must have a short description stating the purpose of the function, what it receives, and what it returns. Comments should be easily identifiable. I should be able to understand your program by reading only the comments. Also include a header at the top of your program (see example below) that must include lab day and TA name.
5 Decomposition: A segment of code that appears more than once should be extracted to form a separate method (in Java) or function (in C). Methods/Functions should be no longer than around 50 lines. Objects are used appropriately.
5 Appropriate data and control structures: Global variables should be avoided and used only when necessary. Method/Function parameters should be used instead. Appropriate looping and decision structures used.
5 Code Layout: Different nested levels should have different indentation, where statements at the same level should have the same indentation. Indent at least 3 spaces. Use either spaces or tabs consistently.

How to turn in your work

Your program is to be submitted electronically via the turnin command on the LINUX machines. The project name for this is mp3. All programs are expected to be written in good programming style.

Turnin your program electronically using the "turnin" command from your CS account as follows:

turnin -c cs340 -p mp3  [your project directory]
where the [your project directory] is the directory name under which you have all your files related to this programming problem. The turnin command will automatically compress the data under your directory, so there is no need to do the compression by yourself.

Notice you can only invoke turnin command on the Linux machines in the lab or after logging into the server machine oscar.cs.uic.edu.

If you want to verify that your project was turned in, look in the turnin directory for a file with your userid. For instance for this project, from your CS account you would type:

    turnin -c cs340 -p mp3 -v

Note that you can execute turnin as many times as you would like, up until the program deadline when turnin will be disabled for this project. Each time you execute turnin for a project, you overwrite all of what you had turned in previously for that project.It does not work in an incremental way.

CS 340 - Fall 2005