CS 4600
Introduction to Intelligent Systems
Project #2
Game Playing

Numbers

Due: September 24, 2003 23:59:59 EST
Please email your code and explanations to Patrick Yaner with the subject line "cs4600 project #2". Also, be certain to include your name in your message.

The assignment is worth 10% of your final grade; however, there are opportunities to earn another point or two.

Why?

The purpose of this project is to explore some of the game-playing algorithms that we have discussed in class, and that are detailed in Chapter 6 of your textbook. Essentially, you will be asked to write several versions of minimax, and to exercise your creativity in coming up with and justifying evaluation functions for two rather interesting games.

Naturally, all of this will be done in LISP. Those of you who didn't do project 1 will probably wish you had.

General Information

Read everything below carefully!

We will make four files available to you from the handouts link:

Compiling code

You may (and should) compile your functions for the competition. To compile a function simply execute:

  (compile 'function-name)

All of your functions should be compiled when your file is loaded. To do this, add the (compile 'function-name) lines at the end of your lisp file for each function you will be using. These will then be executed when the file is loaded into the interpreter.

Vitally Important Details of Naming Conventions

Name your player functions:

  isolation-player-yourgtaccount
  blockem-player-yourgtaccount
  rblockem-player-yourgtaccount

For example, if I had been taking this class in 1990 and had this assignment, my players would have been named: isolation-player-gt7577b, blockem-player-gt7577b, and rblockem-player-gt7577b (gt7577b is burned into my brain; my GT post office number and my SAT score will likely be the last things I remember on my deathbed). The signatures of your isolation and blockem player functions are described below.

Put those functions as well as any other functions you need (that you do not find in utils.lisp, isolation.lisp and blockem.lisp) in a file called:

  player-yourgtaccount.lisp

Append -yourgtaccount to any code that you write. This will prevent conflicts while loading multiple students' players. Bascially, any function or macro or global variable defined in your player-xxx.lisp file should end in -xxx.

To test your code against other players:

  (load "utils.lisp")
  (load "isolation.lisp")
  (load "blockem.lisp")
  (load "player-xxx.lisp")
  (compete-isolation (list #'isolation-player-xxx #'iso-random-player #'iso-random-player))
  (compete-blockem (list #'blockem-player-xxx #'be-random-player #'be-random-player #'be-random-player))
  (compete-rblockem (list #'rblockem-player-xxx #'be-random-player #'be-random-player #'be-random-player))

This will test your player against a random player in a set of games. You can also test your player against itself or any combination of itself and the random player. To test, say, six players against each other in all possible combinations simply execute:

(compete-game (list #'p1 #'p2 #'p3 #'p4 #'p5 #'p6))

Isolation

For this part of the project, you will need to implement a three-player minimax and an appropriate board evaluation function.

The Game

The game has three players: x, o, and v. The players alternate turns, with player x moving first at the beginning of each game.

Each turn, a player can move like a queen in chess (in any of the eight directions) as long as her path does not cross a square already filled in or occupied by another player. After moving, the space vacated by the player is designated as filled and cannot be moved to again. Notice that only the space that was occupied is filled, not the entire path.

The game ends when two players can no longer move, leaving the third player as the winner.

The coordinate (1 1) indicates the top left hand side of the board.

The board is specified as a list of rows. Each row is a list of entries:

The board will always be specified with a border around its outer limits. Note that while the board is specified as a rectangle, any geometry can be defined simply by filling in the appropriate squares with *'s.

You have been provided with:

Your player will be required to run with a set total amount of time. The player should be called by:

  (isolation-player-yourgtaccount 'x xpos opos vpos time-left current-board)

where time-left is remaining time allocated to the player in milliseconds, 'x is which player you are, xpos, opos and vpos are the positions of the players, and current-board is the current state of the board. A useful function to consider for this assignment is (get-internal-real-time). Check out utils.lisp for how it is used. It is also useful to think of dividing the time you have left equally among the subtrees you want to search, stopping along any path when you're coming close to running out of the allocated time.

Your player function should take in the parameters as described above and return a move in the format (row colum). If you cannot move, return (nil nil). The game control code will check for this. If you return an illegal move, the competition code will detect it and you will lose.

What to turn in

You may implement any extensions to minimax that you believe will perform better as well (e.g., alpha-beta pruning might or might not be a good idea). Feel free to explain the extensions to us if you have time.

Please put the lisp code in a file named yourgtaccount.lisp, and your comments in a text file named yourgtaccount.txt with your name with your name and gt account at the top.

Blockem

For this part of the project, you will need to implement a an appropriate board evaluation function and extend your minimax to handle randomness.

The Game

The game has four players: x, o, v, and z, each representing a different color. The players alternate turns, with player x moving first at the beginning of each game. Each player begins with a corner of her own. x has the upper left corner while o, v, and z have the rest of the corners, respectively in clockwise order.

Each turn, a player takes one of her pieces and places it on the board. The first move by each player must start at her corner. Two pieces of the same color must touch corners; however, two pieces of the same color cannot touch along sides. When a piece of any color cannot be played that color must be abandoned. When all colors are abandoned, the winner is the player owning the color with the highest score:

This game is stolen unashamedly from Blokus. The website of the game is available online at http://www.blokus.com/. Feel free to check out that website.

The board is specified as a list of rows. Each row is a list of entries:

The board will always be specified with a border around its outer limits. The coordinate (1 1) indicates the top left hand side of the board.

In addition to the board, each user has a set of pieces to play. The set of pieces is a list where each element of the list is also a list. The list represent a piece and all of its legal orientations. As such each element of that list is a list of rows of the squares covered by that piece in that orientation. The symbol - will represent a blank square and * a square that will be filled. So:

  SET-OF-PIECES     := listof PIECE-ORIENTATION
  PIECE-ORIENTATION := listof PIECE
  PIECE             := listof ROW
  ROW               := how squares are filled in for that row

This representation was chosen because it simplifies matters greatly for us (and for you, really, because you don't have to calculate orientations). Better yet it means that we do not have to guarantee that all orientations are supported, or that the piece-orientation set actually has anything to do with orientations at all.

You have been provided with:

Again, your player will be required to run with a set total amount of time. The player should be called by:

  (blockem-player-yourgtaccount 'x xpos opos vpos zpos time-left current-board)

where time-left is remaining time allocated to the player in milliseconds, 'x is which player you are, xpos, opos, vpos and zpos are the list of pieces still availabe to the players, and current-board is the current state of the board.

Your player function should take in the parameters as described above and return a move in the format (row column piece-and-all-orientations 0-based-index-of-orientation). Note that the upper left hand corner of the chosen piece/orientation will be placed at x, y. If you cannot move, return (nil nil nil nil). The game control code will check for this. If you return an illegal move, the competition code will detect it and you will lose.

The Game, part 2

You will develop players for two versions of this game. In addition to the game described above, you will play a version of this game where the player will not be able to choose the next piece and orientation to play. In particular, you will only be able to choose from half the possible moves (if there are an odd number of possible moves, we will round up), determined randomly. To see what the legal set of moves are, you may call the function:

  (be-get-current-legal-top-level-moves)

To see an example of how to use this function, see the code for the random player provided in blockem.lisp. Note that the random player here works for both the random and non-random versions of this game.

What to turn in

Again, you may implement any other extensions that you believe will help you. Feel free to explain them to us if you have time.

Collaboration Policy

Before turning in your assignment, you are allowed to try your player out against the players written by your fellow students; however, you are quite explictly not allowed to look at any other code or descriptions of code for evaluation functions designed for either of these games (or any games that are similar) except for those provided in the files that we give you or on the blokus site.

You are, of course, allowed to play the games yourself or to play against humans. Again, do not let your discussions turn into any descriptions of an algorithm.

The Tournament

If you wish, your player will be entered into a competition with the other players submitted by the class (both sections). Winners of the competition will receive extra credit for the assigment. Details of how much are to follow.