Course Home | Assignments | Schedule | Submit

Saint Louis University

Computer Science 362
Artificial Intelligence

Michael Goldwasser

Fall 2013

Dept. of Math & Computer Science

Assignment 04

Playing Pente

Due: Tuesday, 12 November 2013, 2:15pm


Contents:


Collaboration Policy

For this assignment, you must work alone. Please make sure you adhere to the policies on academic integrity in this regard.


Overview

You will be developing a player for the game of Pente, using the Python software framework that we are providing. (If you are unfamiliar with the Python programming language, please see me for assistance).

The rest of this document will provide guidance and details about the project. But at the onset, please note that all of your code must be in a single source file, such as robot.py (we will provide you with a template to get started). You are not to make any changes to the rest of our framework.

Also, in addition to submitting the .py file, you must also submit a text "readme" document that provides a choherent overview of all design and algorithmic decisions that you made, and a summary of the components of your Python code.

Your final grade on this project will be based on an evaluation of your source code, your summary document, and on the performance of your player in a Pente tournament against all of the other players!


Pente

The game of Pente is somewhat like a simplified version of go. Players alternate turns, playing one piece of their own color per turn onto grid intersection points. Black will go first and must play in the center of the board (labeled as j10 in our coordinate system). As a special rule (to mitigate black's advantage), black's second move must be at least three rows and three columns away from the center of the board (the area marked by the small circles on the game board).

A player may capture a pair of the opponent's pieces by placing a piece that causes precisely that pair to be surrounded with the opposite color along any direction. That is, if there is a configuration WBB_ then white may capture the two black pieces by placing a white piece in the fourth spot of that sequence. (Note, however, that if there is a configuration WB_W, black may safely place a piece in the third spot of that sequence without being captured.)

A player wins the game either by getting a configuration of 5-in-a-row somewhere on the board, or by capturing a total of 5 pairs of the opponents pieces (hence the name Pente).

A more detailed summary of the rules can be found at http://www.pente.net/instructions.html.


Our Client/Server Game Control

Our software uses a networked client/server model for communication between the game control, two players, and any number of additional observers. If firewalls allow, games could be played across the internet, but we will typically assume that all processes are running on the same machine (that being 'localhost' by default).

Our entire Python code base can be copied from turing:/Public/goldwasser/362/games/.

To begin a game, you must start the game server with syntax

python gameServer.py pente
This software uses port 9000 by default. However, you may choose an alternate port by giving an optional commandline argument such as -p 9001.

Once the server has begun, we need two players in order to start a game. Players are numbered as "player 0" and "player 1". The software is designed so that you can play human-vs-human, human-vs-robot, or robot-vs-robot. A human may take a seat at the game by running the following client program:

python human.py -v
By default, it will look for the game server on the localhost at port 9000, but command line option can be used to change to another port (or IP address). The -v flag visualizes the game with a GUI. (The default, without that flag, is a text-based display and entry.) Also, the software will attempt to connect as player 0 by default, but seat #1 can be indicated with the argument -s 1.

A robot client may also take a seat at a game. You will eventually be writing your own robot, but we offer several samples (discussed below). All will inherit a similar startup interface. A command such as

python robot5.py
has a robot join the game, based on the logic expressed in the robot5.py sample file. Similar to the human client, the robot will attempt to find the server at port 9000 of the localhost and to join the game as player 0; these options can be controlled by commandline arguments. Robots also have a fixed time limit per move of the game (humans have the luxury of unlimited time). By default, it will give 30 seconds per move to the robot; that value can be changed with the -T commandline argument.

Finally, if you are having a game played between two robots, and you want to be a spectator to see the game played graphically (rather than monitor the text dump of the game board output by the server), you may start the program

python kibitz.py -v all

Information about usage and commandline options for all of the above programs can be found by providing a -h flag as a commandline argument.


Controlling (and Killing) Processes

Before we go further in describing the project, we want to emphasize that there is great risk of having out-of-control processes tracing game trees and using up both CPU and memory resources on our computing system. We ask that you be respectful and diligent in your use of our system, and do not leave any robots running unless you are personally monitoring their actions.

Note as well that because both our client and our server programs are multithreaded, you may find it a bit more difficult to cleanly kill a program. Options to try (from simplest to more complex) are:

A note about network ports: The operating system manages the network ports on a machine. If servers and clients connect using a particular port (such as 9000), and the program exit (or are forced to exit), the operating system might not immediately return that port to the pool of available ports. So when quitting and restarting, you may find that you are unable to restart the server on the same port. This will also be the case if there is contention because several students are logged into the same machine (such as turing when using this software). In that case, you can use the -p option for all of the programs to pick some other available port.


Our Robot Framework


Sample Robots

Our code repository includes five sample robots, with increasing complexity.


Advice

Although our robot5 does not embarrass itself, there is enormous opportunity for improving upon its play when developing your own robot. These improvements can come from better evaluation of positions, or more efficient use of computation cycles (thereby getting deeper in the game tree). Some suggestions for potential improvements include the following:

  1. You can develop a more successful heuristic than the one we introduce with robot4. While I like the concept of considering all possible winning locations, the weighting we apply is arbitrary.

  2. Our proposed heuristic completely ignores the issue of captured pieces, other than the indirect effect they have on the board. But there is a more direct advantage to captures as it brings a player closer to the opportunity to win by capturing five pairs.

    For example, at an extreme, it is very difficult to play effectively if you have already given up the capture of 4 pairs, because you must avoid any scenario that leaves you at risk of having a pair captured, thereby ending the game.

  3. A lot of time is spent in computing the heuristic that we provide. In particular, it computes it from scratch for each state.

    Much greater efficiency is achievable by computing the heuristic incrementally as we progress from one state to a resulting state. That is, if sufficient bookkeeping bout a parent state were maintained, it might be possible to efficiently compute how the heuristic has changed as a result of the new move.

  4. The efficiency of alpha-beta pruning is greatly increased if moves are considered at each level in the order from likely best to likely worst, as viewed by the player making the move.

  5. While the rule of only considering moves that are adjacent to an existing tile is reasonable, there are two pitfalls. First, it may be that a really good move is overlooked because it is not adjacent (for example, it may be a piece that lies on the intersection of two extended attacks).

    But more importantly, the rule of adjacency does not seem to be aggressive enough. As we get beyond the opening of the game, the number of adjacent moves grows. The current iterative deepening does not get deep enough in the game to see important tactical combinations, and that is because the effective branching factor is too high.

    I expect that much better results will be achieved if the branching factor can be further limited.

  6. Create an "opening table." That is, why limit yourself to 30 seconds for the first move for white, or the second move for black, or perhaps even the second move for white. There's a reasonably small number of typical game beginnings, and you could do a lot of "offline" computation before submitting your program to decide what move your robot should make early in the game.
  7. Don't just put your feet up when its your opponents turn. Use that time to your advantage! (But how?)
Of course, these are just some suggestions. You are encouraged to experiment with any other ideas that you have to improve the play of your robot.


Online Playground for Testing

As we get further along, I hope to deploy a bunch of robots with varying skill levels (but stronger than robot5), having game servers run around the clock ready to play willing opponents (human or robot).

More details will be provided here...


Tournament

As part of the evaluation of this project (and for fun), we will run a double round-robin tournament with all submitted robots (as well as robots 1 through 5, and perhaps an entry from the instructor), allowing each robot to play once as black and once as white against each competitor. This tournament will be run with a 30-second time limit per move.

The top eight robots from the tournament will advance to the playoffs. The playoffs will be using a single-elimination format, with seeds based upon the rankings from the first tournament (i.e., with #1 vs. #8, #2 vs. #7). Furthermore, we will give the higher seed "home-field advantage" by deciding whether the robot plays as black or as white. This tournament will be run with a 15-second time limit per move. We will likely have this tournament broadcast live in the Linux Lab at a time to be determined.


Submitting Your Assignment

You are to submit a revised version of a Pente robot. All sourcecode that you write must be contained within a single .py file that is submitted. Furthermore, you are to submit a README file that summarizes all design decisions that you made when rewriting the robot. Submit your single .py source code file and your text readme file electronically via the course website (details on the submission process).


Grading Standards

This project will be worth a total of 50 points. 15 of those points will be directly apportioned based on your robot's winning percentage in the initial round-robin. The other 35 points will be based on my evaluation of your code (as greatly guided by your prose description of your approaches from the readme file).

Extra Credit
The two robots that lose in the semi-finals of the secondary tournament will each receive an extra 5 points. The robot that loses in the finals will receive an extra 8 points. The robot that wins the tournament will receive and extra 10 points.


Michael Goldwasser
CSCI 362, Fall 2013
Last modified: Thursday, 31 October 2013
Course Home | Assignments | Schedule | Submit