7.1.0.8

10 — Implementing an Observer

Due Monday, October 29, midnight

Delivery For this assignment, add an Observer directory. Then place the design documents into the Design/ folder and Santorini-specific code into the appropriate Santorini/ sub-directory. Place xobserve into your 10/ folder.

Design Task Your team can finally run the first complete Santorini game between two autonomous ("AI-ish") players. The plan calls for the implementation of a tournament manager as the next step. The manager will continue to use your own, "in-house" players but you can also begin to imagine now how to plug in players from other groups to run competitive tournaments.

Design a tournament manager, which deals with a fixed but arbitrary number of players and runs a round-robin tournament of all players. Clearly, the essence of the manager is basically a function from the players to the result of the tournament, but its description ("purpose statement") must address questions such as how to start the tournament, what to do with broken players, how to report the results, and more. Organize your interface description appropriately; separate the information needed by a client from the one needed by a future implementor.

Implementation Task Modify your referee component so that its context can register an observer. The referee must inform an arbitrary number of observers about three kinds of events: (1) the modification of the game board, (2) the request of a player to take a specific action, and (3) misbehavior by one of the players. For the last one, it suffices to send an informative text back to the observer. Implement an observer component that renders its data representation as plain text a JSON value to STDOUT.

Also produce a harness that runs a game via one referee, two players, and an observer. Call it xobserve. The harness consumes no input; it renders the three kinds of event notification as JSON values to STDOUT:
  • Board, that is, as a JSON array of JSON arrays

  • an Action as either
    • String, which represents the name of a player that is giving up;

    • [Worker,EastWest,NorthSouth], which represents a winning move; or

    • [Worker,EastWest,NorthSouth,EastWest,NorthSouth], which represents a request to move the specified worker and build in the specified directions. The first pair of directions specify the move, the second one the building step.

  • String, which represents an error message or a final result notification.

A successful game is likely to be a roughly alternating sequence of boards and actions ended in a message that indicates who won the game.