Project 1 -- Adversarial Search

Due Tuesday, February 17, 2004, 12:00 noon (electronic submission)

NOTE: This assignment, like others in this class, is due at a particular time. This means that if you are even a minute late, you lose 20%. If you are worried about potentially being late, turn in your assignment ahead of time.

As discussed in class, tic-tac-toe is a simple child's game. It is so simple, in fact, that it fails to hold the interest of most adults who realize that all games will end in a tie if neither player makes a mistake. However, generalizations of tic-tac-toe may still prove to be interesting games. The following assignment is based the idea of 4-dimensional tic-tac-toe (Scott Kim, "Bogglers: 4-D Ticktacktoe," Discover, Vol. 23, No. 10, October 2002, page 82).



4-Dimensional Tic-Tac-Toe

Consider the game boards shown below. Rather than a single 3x3 game board as used in ordinary tic-tac-toe, 4-dimensional tic-tac-toe is played using nine 3x3 game boards arranged in four-dimensional space. Since we can't draw them in four dimensions, we'll draw them as a 3x3 grid of nine 3x3 game boards, as shown. The rows and columns in each 3x3 game board are said to run north-south and east-west, respectively. The rows and columns of the grid of individual game boards are said to run up-down and right-left, respectively. (Note that this terminology only makes sense in a 4D world in which the north-south, east-west, right-left, and up-down axes are all orthogonal to one another).

4D Tic-Tac-Toe

In this game, a tic-tac-toe consists of getting three marks (X's or O's) in a straight line, just as it does with ordinary 2D tic-tac-toe. One difference, however, is what constitutes a "straight line." Since the nine game boards are, in concept, arranged in a four-dimensional space, rather than a two-dimensional space, a straight line can run east-west, north-south, or along either intra-board diagonal as in 2D tic-tac-toe; or run right-left, up-down, or along either inter-board diagonal; or both. An example of three in a row running both east-west and up-down is shown below.

4D Tic-Tac-Toe
The Assignment

You are to write four programs that can play four different versions of 4D tic-tac-toe using minimax with alpha-beta pruning. The four versions differ in their victory conditions:

  1. The first player to get a tic-tac-toe wins.
  2. The first player to get a tic-tac-toe loses.
  3. The player to get the most tic-tac-toes wins.
  4. The player to get the fewest tic-tac-toes wins.
In the first two versions, play stops when the first tic-tac-toe is produced or when all boards are full. In the last two versions, play stops only when all boards are full.

Your programs should be set up to play against an opponent. Your program should take input from standard input and give output to standard output (note that your programs will be run on UNIX or UNIX-like machines). The format of the input and output will be

    (a, b, c, d)
where Your program will be started as either the X-player (who moves first) or the O-player, using either the -X or -O flag, respectively, on the command line when started.

The other command-line flag your program should accept is -A, which should turn on alpha-beta pruning. If this flag is not given, your program should not use alpha-beta pruning.

You may test your program by playing against it using keyboard input or by running two copies of your program as co-processes.

Run each version of your program as needed to answer the following questions:

  1. What is the minimum ply before this game ends? Explain your answer.
  2. What is the maximum ply before this game ends? Explain your answer.
  3. How many nodes are generated without alpha-beta pruning? Explain your answer.
  4. How many nodes are generated with alpha-beta pruning? Explain your answer.
  5. What is the average branching factor of the game tree without alpha-beta pruning? Explain your answer.
  6. What is the average branching factor of the game tree with alpha-beta pruning? Explain your answer.
  7. Is either player guaranteed to win this game if neither player makes a mistake? If so, which player? Explain your answer(s).

If you cannot answer the questions above using the versions of the programs described above, feel free to write additional software that will help you to answer these questions. If you write such additional software, you will need to submit it as well.

For all questions, be sure to EXPLAIN YOUR ANSWERS.



Bonus Assignment

For 5 bonus points, determine whether stopping only when all boards are full is different than stopping when no more tic-tac-toes are possible for the last two versions of the game. If these are not different, explain why they are not different. If they are different, explain why they are different.

For 10 more bonus points, turn in a version of the code that stops when no more tic-tac-toes are possible, rather than when the board is full, for the last two versions of the game.



What to turn in.

You will turn in both a hard copy and an electronic copy of your assignment. Please follow the instructions on how to send electronic copies. Do not send them to my email address.

Both the hard copy and the electronic copy will contain a write-up answering the questions above for each part, plus all source code you used in collecting your results. The electronic copy will also contain four or more executable versions of your code. (One for playing each version of the game, any additional versions you create to help you answer the questions, and a bonus version if you choose to do the bonus assignment.) The electronic copy of your write-up should not be in a proprietary format (such as MS Word); it should be either in plain ASCII text or in a portable format (such as Postscript or PDF). Your source code for each version should be in a single file called 4DTTTi.c and your executable code should be called 4DTTTi, where i is 1 through 4 for the four versions, 5 on up for any additional versions you write, and B for the bonus code.

Your source code should be well structured and well commented. It should conform to good coding standards (e.g., no memory leaks).

Besides the answers and explanations mentioned above, your write-up will include 1/2 to 1 page (roughly 80 characters per line, 50 lines per page) explaining the data structures and algorithms used in your code. This page limitation does not include figures used in your explanation, which are encouraged and may take up any amount of space. (This explanation does not remove the requirement that your code be well commented.)



Other

You may write your program from scratch or may start from programs for which the source code is freely available on the web or through other sources (such as friends or student organizations). If you do not start from scratch, you must give a complete and accurate accounting of where all of your code came from and indicate which parts are original or changed, and which you got from which other source. Failure to give credit where credit is due is academic fraud and will be dealt with accordingly.

As noted in the syllabus, you are required to work on this programming assignment in a group of at least two people. It is your responsibility to find other group members and work with them. The group should turn in only one (1) hard copy and one (1) electronic copy of the assignment. Both the electronic and hard copies should contain the names and student ID numbers of all group members. If your group composition changes during the course of working on this assignment (for example, a group of five splits into a group of two and a separate group of three), this must be clearly indicated in your write-up, including the names and student ID numbers of everyone involved.

Each group member is required to contribute equally to each project, as far as is possible. You must thoroughly document which group members were involved in each part of the project. For example, if you have three functions in your program and one function was written by group member one, the second was written by group member two, and the third was written jointly and equally by group members three and four, both your write-up and the comments in your code must clearly indicate this division of labor.