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

Due: Feb 11, 2008 @ noon

Game Infrastructure

For this assignment, you should develop the basic infrastructure for playing Scrabble 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 AdministratorI {
    // Sequence contract
    // registerPlayer . registerPlayer . playGame

    void registerPlayer(PlayerI p);

    String playGame();
    // starts the game, returns a string indicating who won
}


interface PlayerI {
    // Sequence contract
    // draw . (takeTurn | inform | getName)* . gameOver

    void draw(Tile[] ts);
    // player is informed of its initial draw.

    void takeTurn(TurnI t, BoardI b, int tilesleft);
    // player is granted a turn and told about the current board.

    void inform(String s);
    // server sends a message to the player

    String getName();
    // the player reports its name.

    void gameOver(int finalScore, boolean won);
    // informs the player that the game is over
    // their score and if they won.
}


interface TurnI {
    // sequence contract
    //  exchangeTiles | ((placeTile | placeBlank)+ . donePlace)

    Tile[] exchangeTiles(Tile[] ts);
    // hands in the tiles ts
    // result is the new tiles.

    void placeTile(int x, int y, char tile);
    // place the tile at coordinates (x,y)
    // call this method once per (non-blank) tile placed.

    void placeBlank(int x, int y, char tile);
    // place the tile at coordinates (x,y)
    // call this method once per blank placed.

    Tile[] donePlace();
    // call this method to indicate no more tiles
    // will be placed (this turn). Result is 
    // the new tiles.
}

interface Tile {}
interface Blank extends Tile{}
interface Nonblank extends Tile {
  getChar();
}

Whether you use Java or not, you must structure your program as these interfaces suggest. In Java, you must use these interfaces.


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.

Mandatory Contracts

The following invariants govern the interactions in Scrabble:

  • The sequences 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 out some contracts to add to it.



CMSC 22001: Software Construction