8 — The Observer
Due Thursday, 07 November 2024, 11:59:59pm
Purpose This milestone has two distinct learning goals:
T to develop a “non functional” but helpful component; and
T to ensure that the core system can cope with components that violate the “business logic.”. These components act in a well-behaved manner in all other ways.
Composing the already-existing visualization pieces into a complete observer is a good investment for every software system that deals with geometric ideas. While it does not enhance the functionality of the system per se (allowing players to connect and play refereed games) the observer will help you understand how games proceed and how games may go wrong. It is essentially a problem-specific debugging aid.
Delivery Place the product of this week’s milestone into your git repo as follows:
for the Programming Task, place observer.PP into Bazaar/Referee/;
for the Design Task, place remote.md into Planning/
for the Testing task, place xgames-blogic and Tests/ into a top-level repo directory named 8
Programming Task Implement an observer component with which dev ops can watch and inspect a game from a referee’s perspective.
Look into the Observer design pattern.
it saves the states it receives as PNG files in a directory called Tmp/, using the names "0.png", "1.png", and so on.
The Tmp/ directory should be created at the place where the program is run.
- it displays the states it receives as images in a graphical user interface (GUI). This GUI must support at least three interaction capabilities:
A next functionality shows the next state of the game, if it is available.
A previous functionality shows the previous state of the game, if it is available.
A save functionality saves the current state as an instance of Game in a file of the user’s choice.
Protocol The observer must support at least two pieces of functionality: (1) a receive-a-state functionality, which consumes a state; and (2) a game-over functionality, which alerts the observer that no more states will become available. The referee will use the first method to inform the observer of a change in state is completed and at the very end of the game (why?). The second piece of functionality is used as the referee shuts down.
The observer is wired into the referee only when a devop requests it. See below for how such a request is specified on the command line.
Design Task The time has come to prepare for turning your monolithic software system into a distributed one. Imagine your referee managing a game with all the players from your peers in class or your player participating in a game that one of your peers organizes.
Then design a protocol for gathering players, launching a game, and reporting the result. Use Logical Interactions as a starting point. Your document should combine English, schematic JSON data definitions (if needed), and sequence diagrams (if needed) to specify a protocol that you and your peers can implement.
Keep in mind our Bazaar.Com, a Plan while you work on a design task.
Testing Task Create a test harness named xgames-blogic. The harness consumes its JSON input from STDIN and produces its results to STDOUT. Create ten tests ([0-9]-{in,out}.json) and place them in the specified Tests/ folder.
A test case always consists of given inputs and expected outputs. For this
course, a test consists of a pair of files: n-in.json, the input file, and
n-out.json, the expected output file, where n is an integer between 0
and the requested number of tests (exclusive).—
*ActorsA, representing the actual players;
the (maximally useful) *Equations; and
a Game state.
Functionally, xgames-blogic performs the same computation as the test harness of
7 —
The output format is the same as for 7 —
CONSTRAINT A *ActorsA array contains at most 6 items. |
CONSTRAINT The names of any two different ActorAs must be distinct. |
|
- a JSON array of four elements: [ActorName, Policy, "a cheat", Cheat] |
|
- "use-non-existent-equation" |
INTERPRETATION Denotes a player that in response to being granted a turn, |
requests an exchange that is not according to any given equation |
- "bank-cannot-trade" |
INTERPRETATION Denotes a player that in response to being granted a turn, |
requests an exchange according to some given equation that the bank cannot currently support |
- "wallet-cannot-trade" |
INTERPRETATION Denotes a player that in response to being granted a turn, |
requests an exchange according to some given equation that its wallet does not currently support |
- "buy-unavailable-card" |
INTERPRETATION Denotes a player that in response to being granted a turn, |
requests the purchase of a card that is not among the currently visible ones |
- "wallet-cannot-buy-card" |
INTERPRETATION Denotes a player that in response to being granted a turn, |
requests the purchase of a card that its wallet cannot currently afford |
A cheating player cheats when possible; otherwise |
it returns the results dictated by the chosen strategy. |
Demand for Observers If the harness is run with the command-line flag "--show" (that is two dashes!), the game observer is attached to the referee; otherwise the referee runs in the usual black-box mode.
$ xvfb-run ./xgames-blogic xgame-with-observer...