Homework #3: Game Playing
Specifications Due: October 8th
Full Program Due: October 24th, 2007

The written part is due at the beginning of class on 10/8. The program should be submitted online by 2:15 on 10/24 to courseworks using the submission instructions.

For this assignment you are to write a program that can play Connect-Four. You can assume that you are playing against one other opponent. Your opponent can be either a human or a computer

Playing Connect 4

You are given a board consisting of 8 columns and 12 rows. At each turn, one of the two players places his/her piece in a column. It will go into the first free row of that column. You can imagine placing the piece at the top of the column and having it float to the bottom.

The goal of the game is to get four of your pieces in a row (either across a row, down a column, or on a diagonal). The first person to get four in a row wins.

In traditional Connect 4, the board is 7 columns by 6 rows. We deviate from the traditional game in two ways:

  1. Our board is larger (12 rows instead of 6; 8 columns instead of 7)
  2. We will allow wraparound for the 4 pieces in a row. For example, if player A has two pieces in the leftmost columns of row 2 and two pieces in the right most column of row 2, then player A wins.
The rules and further details are provided in the two websites below.

Strategy: There is some strategy to playing Connect 4. The websites linked below have information on strategy and you are welcome to search the web to find other tips on strategies. Note that you can undoubtedly find code online for the traditional version of Connect 4. It is quite likely that code will be more complicated than what you are required to implement for the assignment. While it is OK to look for strategies online, copying code that you find online will be considered cheating.

     Rules of Connect4 and links to strategies  
     You can play Connect 4 with a computer here.    

What to turn in

The written assignment and programming assignment each will be graded out of 30 points. For the final submission, you will use the online submission process to turn in your code and a README file. All code should be working and well documented. You will be graded in part based on this documentation.

The README file should include:

  1. A description of your approach and any special points that you think we should know about,
  2. Details on how to run your code
  3. A short paragraph explaining how you did each of the following requirements and the name of the class that implements it in your program: minimax search, alpha-beta pruning, move generator, and evaluation function.

Assignment details

Implementation: You are to implement a minimax search using alpha-beta pruning. You should set up your program so that search depth can be a user-provided parameter and you can run your program with different levels of lookahead. You should implement an evaluation function that estimates how good a particular game state is. Consider various strategies, such as the ones given on the web sites, when implementing your evaluation function. You will be graded in part on the creativity you show in implementing your evaluation function. In your program, you will need to keep track of the state space, which should include the layout of the board. You will also need to keep track of pieces in a row; when you make a move that results in 4 pieces in a row, your program should declare that you are the winner. Finally, if you make an illegal move, then you lose the game.

Directions for the written part of the assignment and specification are provided here:. Note that the written part also includes some written book assignments both on past topics (search) as well as game-playing (alpha-beta pruning).

Tournament: Following the due date, there will be a tournament in which your programs will be pitted against each other. Entering the tournament is optional; everyone entering the tournament will receive 10 points of extra credit and there will be a series of extra credits for teams that win at each round.

Interface: Since this is a two-player game, you will need to be able to pit your program against a human player (for development and testing) and against other computer players for the tournament. To facilitate this, we are providing a module that you will need to interface with. This module will maintain the state of the game, make your moves, report your opponent's moves to you and provide a GUI for the game. Details can be found on this page: Connect4.

Technical details

You must write all your code in Java. Code written in other languages will not be accepted. Your code should be compatible with Java 1.5 or higher. It should run on CS machines (currently using Java v1.5.0_01) or, if you don't have CS accounts, on CUNIX (currently using Java v1.6.0_02).

The write-ups may be handwritten or printed and should be turned in at the beginning of class on the day of the deadline. Softcopy write-ups should be provided as plain-text files or PDF documents. Other formats will not be accepted.

Late Policy and Penalties

As per the late policy of the class, you will lose 1.5 points (5%) per day that the assignment is submitted past the deadline. For this purpose, any amount of time greater than one minute counts as a full day. Assignments will not be accepted after a period of 7 days beyond the deadline. A further extension may be granted if and only if the instructor is contacted before the end of the 7-day late period, provided that the circumstances are extreme enough to warrant an extension. In this case, the late penalty will be determined on the basis of the individual case. If a request for an extension is not granted before the end of the 7-day period, the assignment will not be accepted under any circumstances.

You are required to submit working and documented code for assignments involving programming. If we have to edit your code in any way in order to get it to run, you will be penalized depending on the extent of the changes required. If we are unable to run your code, we will ask you to uncover the problem and you will be penalized depending on the changes as well as the amount of time taken to fix the code. Penalties for non-working code will be applied in the form of a percentage of the points carried by the assignment part in question.

Write-ups turned in on paper are due at the beginning of the class on the day of the deadline. Hardcopy write-ups turned in at the end of class will be penalized by 1 point.

General notes

Make sure that the source code is clear and well-documented internally as hand annotations will be ignored. The source code must also outline how it should be tested. Clear programming style and thorough testing will account for a substantial portion of your grade for the programming part of this assignment.

Sharing and re-using ideas, solutions and code with other students is prohibited. Please refer to the Collaboration policy page if you have any questions regarding the level of discussion permitted.

Refer to the Submissions page of the class website for specific instructions regarding assignment submissions. Please do not email assignments to any of the TAs.