Homework 1 (due 9/17 by 6 p.m.)

Group assignment (100 pts)

In this assignment you will write a general program that plays Connect four (an extension of Tic-Tac-Toe).  The game is typically played on a seven by six grid by two players.  Players alternate in placing coins, where the constraint is that coins can be placed only at the bottom row or on top of other coins (assuming that the game board is standing vertically and coins are inserted in columns like in slots).  The goal is to connect four coins horizontally, vertically, or diagonally.  The first player to connect four coins wins.

Check out some of the online versions to get an idea of the game if you are not familiar with it:

Your program will consist of two parts:
  1. A "computer player" (which is basically the minimax procedure with alpha-beta pruning plus an evaluation function).
  2. The playing environment for you to test the player (including input functions for the human player and a graphical display of the board).
After all groups have turned in their code, a tournament will determine the best "computer player" (the winning group will get bonus points!).

Before you start coding, first agree on a representation of the board (note that there are many ways of doing this, but some are better then others; you might want to choose a time/space-efficient representation): you could, for example, represent the board as an array of characters, where " " (space) indicates the empty field, "O" and "X" the two players' pieces.  Once you have represented the board, define your own connect4 class, which contains all the functions necessary to play the game, including the evaluation function and the minimax search with alpha-beta pruning.
// your connect4 class
public class Connect4<GID> implements Connect4Interface {
<put in your code here>

<GID> here denotes your group identifier (i.e., Group1, Group2, etc.)

Note that your class must implement the following Connect4Interface interface:
// interface that should be implemented by your connect4 class
public interface Connect4Interface {
 // this initialized the board
void initializeBoard(int rows,int cols);

// player X places a piece in a row
void moveX(int col);

// player O places a piece in a row
void moveO(int col);

// tells the computer to be player X
void setComputerX();

// tells the computer to be player O
void setComputerO();

// displays the current board on the screen
void displayBoard();

// gets the move from the human player, returns the column
int getHumanMove();

// returns true if the current board is a win for X
boolean isWinX();

// returns true if the current board is a win for O
boolean isWinO();

// returns true if the current board is a tie, i.e., all positions are filled
boolean isTie();

// tells the computer to make a move and return the column
int getComputerMove();

// sets the ply number for minimax search
void setPly(int ply);

// sets a parameter determining whether to use alpha-beta pruning
void useAlphaBeta(boolean on);
}

The main loop for playing connect4 based on this interface then could be something like this (we will use the interface to be able to run a tournament with the various connect4 programs):

void play(Connect4Interface c4,int rows, int cols, boolean humanX, int ply, boolean usealphabeta) {
  // player X always starts
boolean turnX = true;

// initialize the board
  c4.initializeBoard(rows,cols);
  c4.setPly(ply);
c4.useAlphaBeta(usealphabeta);

// let the computer know who is who
if (humanX)
c4.setComputerO();
else
c4.setComputerX();

// loop until the game is over
while (!c4.isTie() && !c4.isWinX() && !c4.isWinO()) {
  if (turnX) {
    c4.moveX(humanX ? c4.getHumanMove() : c4.getComputerMove()); 
  turnX = false;
  }
  else {
    c4.moveO(humanX ? c4.getComputerMove() : c4.getHumanMove());
    turnX = true;
}
  c4.displayBoard(); 
}

// print the results
if ((c4.isWinX() && humanX) || (c4.isWinO() && !humanX))
System.out.println("Humanity prevails");
elseif (c4.isTie())
System.out.println("Tie");
else
System.out.println("Silicon prevails");
}

Note: it will be helpful to write--in addition to the above and to the evaluation function, minimax-search with alpha-beta pruning--lots of little helper functions for the evaluation function (e.g., functions that access the board and report the presence of certain properties such as three Os in a row).  The evaluation function is critical as we will test your code with different values for "ply" and with different board sizes (so make sure you don't make any assumptions about the size of the board--the 6x7 board is only the standard size, we will write general functions that work for boards of all sizes!).

Code and comments

Grading programs without comments is extremely difficult.  Hence we ask you to provide a short synopsis at the beginning of each function, which indicates the author(s) of the function and describes what it does (if the function is longer than a few lines, please also add comments within the function body indicating what you are doing).  We expect your code to be well documented and will take off points for sparsely/badly documented code!

Academic honesty

The goal of this assignment is to familiarize you with game playing (and also CommonLISP, if you do not know it already).  Do not copy any existing program as this is considered plagiarism and violates the academic honesty policy.  You may look at the pseudo-code implementation in the AIMA book, of course, but not at any version of minimax search with alpha-beta pruning (be it in JAVA or any other programming language).  Also, do not exchange information with other groups!  However, you are encouraged to post general questions about this assignment to the listserv.

Submission information

We have created "group" directories in the course dropbox space (group1,group2,group3, etc.):

  /afs/nd.edu/coursefa.04/cse/cse471.01/group-dropbox/

where group members have full permission to their respective directories.  Please submit all your code in a file called

  c4<GID>.java

in  the hw1 subdirectory in your group directory before class on the day the assigment is due.

Furthermore, submit an ASCII text file called

  info<GID>.txt

which lists the responsibilities of the group members (i.e., of which part of the problem and code they were in charge).

Individual assignment (100 pts)

Part 1 (25 pts)

Discuss the claim that "exhibiting intelligent behavior is a necessary, but not sufficient condition for being intelligent".  Do you think that this is true?  If so, why?  If not, why not?  What is implied by such a view?  What would change in your opinion if the claim were "reversed" as in "exhibiting intelligent behavior is a sufficient, but not necessary condition for being intelligent"?  Are there sufficient conditions for being intelligent?  (You might want to include in your discussion the Turing Test and other examples we have used in class and/or can be found in the course texts).

Write two short paragraphs (about 200 words each at most) about the above topic.  Be as precise and concise as you can.  What counts here is not whether you are right or wrong, in fact, there might not be a "right answer".  Instead, emphasis is put on your arguments, how you present them, and how conclusive they are.

Part 2 (75 pts)

Solve the following problems from the book: 2.2., 2.5, 3.11 (graduate students only, extra credit for undergraduates), 6.8, 6.14

Academic honesty

You are not allowed to discuss it with other people in your class (or anybody else for that matter, except the instructors of the course), but you are allowed to refer to books, articles, or any material that you might find useful (in this case include a reference to the text!).  If you have any questions, please ask us (i.e., your instructors) directly!  However, you are encouraged to post general questions about this assignment to the listserv.

Submission information

Turn in an ASCII (!) version of your essay and the answers to the five problems in file called

  hw1.txt

in the hw1 directory in your space in the course dropbox

  /afs/nd.edu/coursefa.04/cse/cse471.01/dropbox/<yourAFSid>/hw1/
 

Good luck!


This page is maintained by:
Matthias Scheutz
Copyright © 2004, University of Notre Dame
All rights reserved.
Last revised on September 3, 2004