CMSC 22001: Software Construction Assignment 5: Game Infrastructure and Contracts

Due: Feb 8, 2006 @ 3pm

Game Infrastructure

For this assignment, you should develop the basic infrastructure for playing Carcasonne and add contracts to it and to your rules checker.

The program provides an administrator and a player. The administrator manages the board, the remaining tiles, and the game itself. Each player registers with the administrator. Once the game is started, the administrator gives each of the players one turn per round. Note that this assignment does not require you to implement any players, except possibly to test your administrator.

Here is a starting point for your design.

interface Player {
  // inform the player what color it is
  // color must be one of "black" "blue" "red" "green" or "yellow"
  // the player responds with its name.
  String startGame(String color);

  // the player takes a turn on the given map
  // with the given tile to place and the number
  // of meeples that are unplaced.
  Move doMove(Map map, String tile_id, int meeples);
}

interface Map {
  .... 
}

class Move {
  int x;
  int y;
  int rotation;  // 0, 1, 2, or 3
  MeeplePlacement meeple;
}

interface MeeplePlacement {}

class PlaceMeeple implements MeeplePlacement {
  // one of "left" "top" "right" "bottom" "center"
  // refers to the edge after the tile has been rotated
  String edge;

  // 0 if the edge is not a road edge
  // otherwise indicates which region on the edge,
  // counting clockwise around the edge
  int loc;
}

class NoMeeple implements MeeplePlacement {}

interface Game {

  // add a player to the game
  void register(Player p);
  
  // start a game
  void start();
}

Whether you use Java or not, you must structure your program as these interfaces and classes suggest. In Java, you must use these interfaces and classes. Of course, you may implement things differently internally; consider this an interface specification.


Contracts

For some contracts, blame for failure lies with the player and for some, blame lies with the administrative infrastucture. For those where blame lies with the administrator, abort the program when a failure is detected. For those where the blame lies with the player, inform the player that they have violated the contract (if possible) and kick them out of the game, but do not stop the game for the other players.

Behavioral Contracts

The following invariants govern the interactions in Cacassonne:

  • The constraints described in the above interfaces must hold.
  • When a player indicates their move, it must be legal.
Determine which invariants should protect which methods, and turn them into method contracts. Implement the contracts manually or use some contract system in your PL of choice.


Your Own Contracts

As we discussed in class, contracts belong at key interfaces in the program. The above contracts protect the administration of the game from the players (and vice-versa). Find another place in your own organization of your program that would benefit from contracts and work our some contracts to add to it.



CMSC 22001: Software Construction