On this page:
Player API
Sequences
8.3.0.10

Logical Interactions

Matthias Felleisen

Player API

    setup : Map x Natural x Cards[] --> Void

    // sets up this player with the basic game pieces

    

    pick : Set[Destinations] --> Set[Destinations]

    // asks this player to pick some destinations for the game

    // an return those not chosen

    // .. relative to the given map

    

    type Action:

     An action is either

     -- an indication to get more cards (more_cards below) or

     -- a Acquired

    play : PlayerState --> Action

    // grants this player a turn

    

    more_cards more : Cards[] -> Void

    // hands this player some cards

    

    win : Boolean -> Void

    // did this player win?

Sequences

The interaction between Racket player components and the Racket admin framework is governed by the set of following interaction diagrams.

Setting Up a Game

    

    referee                         player (p_1) . . . player (p_n)

      |                                |                 |

      |                                |                 |

      |     setup(map,r,cards)         |                 | % the map for this game

      | -----------------------------> |                 | % the number of rails

      |                                |                 |

      |     pick(destinations[])       |                 | % given these 5 destinations,

      | -----------------------------> |                 | % where does the player

      |     destinations[]             |                 | % want to go (return 3)

      | <============================= |                 |

      |                                |                 |

      .                                .                 .

      .                                .                 . % repeat down age

      .                                .                 .

      |                                |                 |

      |     setup(map,r,cards)         |                 |

      | -----------------------------------------------> |

      |                                |                 |

      |     pick(destinations[])       |                 |

      | -----------------------------> |                 |

      |     destinations[]             |                 |

      | <=============================================== |

      |                                |                 |

Playing Turns

    

        referee                         player (p_1) . . . player (p_n)

          |                                |                 |

          |   play(state)                  |                 | % player receives:

          | -----------------------------> |                 | % - current state            

    

    action 1:

          |     more_cards                 |                 |

          | <============================  |                 | % request cards

          |     more(cards[])              |                 |

          | -----------------------------> |                 | % if there are cards

          |                                |                 |

          |                                |                 | % no cards available     

          .        . .

    action 2:

          |     Connection                 |                 | % acquire connection

      +-- | <============================  |                 |

      |   .                                .                 . % if legal:

      |   .                                .                 . % referee modifies game state

      +-> .                                .                 . % otherwise:

          .                                .                 . % kick player out

          .                                .                 .

          |   play(state)                  |                 |

          | -----------------------------------------------> |

          |     action                     |                 |

          | <=============================================== |

          |                                |                 |

          .                                .                 .

          .                                .                 .

          .                                .                 . play until end condition:

          .                                .                 .

          .                                .                 . % When one of the player’s number of

          .                                .                 . % rails drops to 2, 1, or 0 at the  

          .                                .                 . % end of a turn, each of the all    

          .                                .                 . % other remaining players get to    

          .                                .                 . % take one more turn.               

          .                                .                 .                                     

          .                                .                 . % The game also ends if every       

          .                                .                 . % remaining player has had an       

          |                                |                 | % opportunity to play a turn and the

          |   play(state)                  |                 | % state of the game does not change.

          | -----------------------------> |                 |

          |     action                     |                 |

          | <============================  |                 |

          .                                .                 .

          .                                .                 .

          .                                .                 .

          .                                .                 .

          |   play(state)                  |                 |

          | -----------------------------------------------> |

          |     action                     |                 |

          | <=============================================== |

          |                                |                 |

          .                                .                 .

          .                                .                 .

Scoring a Game

    

    referee                        player (p_1) . . . player (p_n)

      |                                |                 |

      |                                |                 |

      |     win(Boolean)               |                 |

      | -----------------------------> |                 | % true means "winner"

      |                                |                 | % false means "loser"

      .                                .                 .

      .                                .                 .

      .                                .                 .

      .                                .                 .

      |     win(Boolean)               |                 |

      | -----------------------------------------------> |

      |                                |                 |

      |                                |                 |

Convention The % parts on the right are interpretive comments. ~~

    ------> are calls

    <====== are returns

A missing return arrow means that method must successfully return void.

Termination of Interactions An interaction between the referee and any player is discontinued if the player
  • breaks the rules (a “business logic” bug)

  • raises an exception (a safety bug)

  • takes too long for a computation (a DoS bug).

We do not worry about a player that exploits shared-memory allocation of data representation. These terminations are not specified in the sequence diagram.

Naturally, if a referee has to eliminate the last player, the game is over.