Project 1 - Connect Four

Due - Monday, September 18, 2006

The goal of this project is to give you an opportunity to practice using Java.

In this project, you will write a program that allows two users (both human) to play a game of Connect Four. You can visit the following website for an example of how the game works: http://www.mathsisfun.com/games/connect4.html.

The game is played using a board with 7 columns and 6 rows. Each player is assigned a color, one player is red and one player is black. At each turn, a player places a checker of her color in the top empty space of one of the columns. Once a checker has been placed, your program will check to see if a player has won the game, or if the board is full. A player wins if four checkers of her color are adjacent either vertically, horizontally, or diagonally. If there is a win or tie, the program will print an appropriate message and exit. If not, the next player takes a turn.

Your program will represent the board using text only. For example, your program might display:
| | | | | | | |
---------------
| | | | | | | |
---------------
| | | |R| | | |
---------------
| | | |B| | | |
---------------
| | |R|B| | | |
---------------
|B|R|B|B| | |R|
 1 2 3 4 5 6 7
A user can specify where she would like to place her checker by simply specifying the column number.

Implementation Requirements and Hints

  1. Your program must use classes where appropriate. You should have at least two classes in addition to a driver that contains your main function. When designing your classes, think about the objects that are used to play the game and the actions performed with or by each object.

  2. If a user chooses to place a checker in a full column, an error message should be displayed and the user should be prompted for another selection.

  3. Recommended progress:
    1. 9/4 - Complete your design and algorithm. Your design should include an overview of each class you plan to implement, including the data members and methods you anticipate using. For each method you plan to implement, you should outline the algorithm for that method. The algorithm provides a step-by-step description of the functionality you will implement. Though your program need not use a sophisticated design, you should use classes where appropriate. At minimum, I recommend using a Board class that will keep track of plays and a UserInterface class that will prompt the players for input.
    2. 9/11 - Complete the implementation of the logic that determines whether a player has won. As you work on this, I would highly recommend that you first implement and test the code to check for a horizontal win, then move on to a vertical win, then move on to a diagonal win. You can test your logic by hard-coding various board configurations and determining whether you correctly identify wins.
    3. 9/15 - Complete the implementation of your user interface. The user interface should prompt the user (both players) for input when appropriate, verify the input entered, and provide any necessary output.
    4. 9/18 - Integrate the pieces of your program. Thoroughly test your code.

Extra Credit Opportunity

For extra credit, implement a computer-based player. Your computer-based player will play against the human player by using an intelligent algorithm for determining where to play for each turn. If you wish to take advantage of this opportunity, schedule a meeting with me prior to beginning your implementation. We will discuss possible algorithms and I can give you some hints.

Due 9:40AM Monday September 18, 2006

  1. Complete and submit your working code. Turn in a hard copy in class and place a copy of your .java files in /home/submit/cs112/username.
  2. Make sure that each function is well documented. Your documentation should specify the type and function of the input parameters and output.
  3. Run your program on a variety of inputs ensuring that all error conditions are handled correctly.
Note: No portion of your code may be copied from any other source including another text book, a web page, or another student (current or former). You must provide citations for any sources you have used in designing and implementing your program.
Sami Rollins