COMP 303 Fall 2010

Milestone 2 - Game Engine and AI

$Revision: 1.3 $ $Date: 2010/09/28 16:20:43 $


To provide an opportunity to gain additional experience and skills with:

Required Problem 1 - AI Robots

Note the required problems do not need to be completed sequentially. It more desirable to work on them in parallel.

Design, implement, and test three AI robots that implement the IRobot interface. A RandomRobot will play correctly (i.e., respect all the rules), but will choose randomly among all legal options whenever a choice is required. A PredictableRobot will play always with the same strategy: of all the legal moves, plays the highest-scoring (or highest-ranked) card that is guaranteed not to win the trick. If none is available and at least one more player will play, play the lowest card; Otherwise, play the highest-scoring card. If a suit must be chosen, choose in order: Clubs, Diamonds, Spades, Hearts. Finally, a SmartRobot will play correctly, and also display some evidence of strategy (e.g., by inspecting the game state to determine what others have played and acting appropriately).

Your SmartRobot must be demonstrably superior to RandomRobot and PredictableRobot (see below).

Required Problem 2 - Game Engine

Implement a game engine module that can store all game state a provide public methods to allow clients to modify the state of the game and react to it through observers. This module should be made accessible through class that will control the state and playing of the game for one human and 3 computer players. This state should include, for example, the cards played, the state of the deck, the score of each player, which player is the dealer, etc. This module should have no GUI, but should provide an API allowing clients to "play" the game, i.e., change the state of the object to allow it to control the playing one complete game (which involves multiple hands). The Game Engine should support playing multiple games without restarting the application.

It is your responsibility to design a module with an interface meeting the principles seen in class, and that will make it as convenient as possible to create the user interface. It should also be possible to register observers of the game state.

Note that the game engine should be purely reactive. It should not control the flow of the program (e.g., through an event loop.

Besides the main GameEngine class, you can create as many helper classes as necessary to solve the problem.

It should be possible to log all the actions of the game engines through a logger. For this functionality, use the popular Log4J API (hint: it is already linked in your project). You need to log all actions necessary to replicate games played, e.g., by hand using real cards.

You must provide a set of unit tests that demonstrate and test your Game module. You should have unit tests for each public method of your GameEngine class (except trivial getters and setters).

Required Problem 3

Provide a driver program (i.e. a main method) that simulates playing a game using GameEngine. Note that the role for the driver is not to allows humans to play interactively, but merely to demonstrate you GameEngine API in action. For example, Driver code would typically look like:

GameEngine lEngine = new GameEngine();
// Display results

and so on. It should be possible to turn the logging of the game engine commands on or off, as needed. For example, your console output could look like this:

INFO - Entering application.
INFO - Dealer is Jenny (2)
INFO - Deck shuffled
INFO - Bobby:5C 8C 6D 7D TD QD KD 5S 7S TS AS 8H AH
INFO - Shorty:4C QC KC AC 4D 4S 6S 8S 2H 3H 5H QH KH
INFO - Jenny:2C 3D 5D JD AD 2S 9S JS QS 4H 7H 9H TH
INFO - Ziggy:3C 6C 7C 9C TC JC 2D 8D 9D 3S KS 6H JH
INFO - Bobby passes 6D TD 5S Shorty
INFO - Shorty passes 4C KC 5H Jenny
INFO - Jenny passes AD 2S QS Ziggy
INFO - Ziggy passes 7C 9D 3S Bobby
INFO - Bobby:5C 7C 8C 7D 9D QD KD 3S 7S TS AS 8H AH
INFO - Shorty:QC AC 4D 6D TD 4S 5S 6S 8S 2H 3H QH KH
INFO - Jenny:2C 4C KC 3D 5D JD 9S JS 4H 5H 7H 9H TH
INFO - Ziggy:3C 6C 9C TC JC 2D 8D AD 2S QS KS 6H JH
INFO - Jenny plays TWO of CLUBS
INFO - Ziggy plays SIX of CLUBS
INFO - Bobby's score: 8
INFO - Shorty's score: 2
INFO - Jenny's score: 14
INFO - Ziggy's score: 0

Your driver should allow autoplay between 4 robots as well as play between 3 robots and a human. Think carefully how this can be designed as effectively as possible. Program your driver to automatically play 10000 games between four of your IRobots (two random, one predictable, one smart), record the number of games won by each type of robot, and output the number of games played and the number won by each type of robot. If your smart robot does not win the highest number of games, keep working on it.

Bonus Problems

To make the game more exciting, and to obtain more points on your project. Only tackle bonus problems if you can complete the basic requirements. Bonus marks will be at the discretion of the markers based on the sophistication level of the bonus features, up to a maximum of 20% of the total mark for the milestone. Note that super-trivial extensions may not receive extra marks. The following are ideas for extension. Other ideas may be considered: please discuss them with the instructor.

Bonus Problem A - Statistics

In the GameEngine, build in support for accumulating stats about the performance of the players in persistent storage.

Bonus Problem B - Save/Load

In the GameEngine, build in support for saving the game (at any point), and loading a previously saved game.

Bonus Problem C - Plug-in framework for robots

In the GameEngine, build in support for loading an open-ended number of different robot types, and using these types in the game.

Bonus Problem D - Adjustable hardness

Make the "intelligence" of your smart robot parameterizable (e.g., from 0 to 100). Demonstrate that the higher the number, the more games the robot wins.


A zip file containing:
  1. All the code and binaries of your project.
  2. All the unit tests you developed for the Game Engine and Robots.
  3. The code of the test driver. When launched, the driver should run without problems, auto-play 10000 games (with logging off), and report the win statistics for the different robots.
  4. A UML state diagram modeling the GameEngine class. The diagram must be in jpeg format. Note that by state diagram, we mean a state diagram, not a class diagram.
  5. A text file (ASCII) with maximum one page of text explaining your main design, addressing the design points mentioned in "Required Problem", and explaining the rational behind the AI "behavior" you have implemented. In the file, include the win statistics for your robots, and details of the design and implementation of any bonus feature.
Please submit through WebCT. See the schedule for the deadline.


This part will be marked out of 35 and will be worth 35% of the overall project grade. It will also be the backbone for your GUI so it is important that you do it well. In marking your project, we will looking for the following points: