Teaching
670 S '07
 
Projects
Presentations
Programming
 
Squadron Scramble
Aircrafts
Project 1
Project 2
Project 3
Project 4
Project 5
Project 6
Project 7
Project 8
Project 9
Project 10
Project 11
Project 12
Project 13

Project 5

Due date: 2/10 : NOON

Representing Players and Turns

It is now time to look at the big picture again. The eventual goal is to have a Squadron Scramble game system that can pitch a number of different automatic players against each other. You may even consider including a human player later.

The last project created the basic ingredients for an automatic player: representations of cards, decks, stacks, hands, and squadrons. Based on these you can now implement an automatic player and test it rigorously before you link it into a game administrator (possibly your own).

New Task 0: [POINTS: 5, by Friday NOON only] Draw a sequence diagram for the implicitly proposed interaction between the game administrator and players of Squadron Scramble.

Task 1: [POINTS: 20] Implement a Squadron Scramble turn. The purpose of a turn object is to represent the (sub)state of the game that the player needs to know to play the game, assuming the player encapsulates its own state. In our case, this means the deck, the discard stack, the discarded bomber squadrons of the other players. For completeness sake, my turn representation also includes the name of the player whose turn it is. (This alludes to the idea that the administrator could also keep track of the player's state and hand it back for a turn.)

In addition, a turn must also include methods that allow the player to perform all legal game actions. As discussed in class, a software designer must make a trade-off here, either equipping the turn with imperative actions that record the actions or demanding a record of the actions as a part of the player's take-turn return values. The signature of turn shows that I have come up with a compromise solution: the actions of taking cards from the deck or stack are imperative capabilities of the turn object while attacks and discarded squadrons are recorded in the result of the player's take-turn method.

Turn Interface:

;; Turn-to-Player INTERFACE

   turn-card-on-deck?        : turn/c -> boolean?
   ;; is there are a card on the deck? 

   turn-get-a-card-from-deck : turn/c -> card/c
   ;; get a card from this turn's deck

   turn-stack-inspect        : turn/c -> (listof card/c)
   ;; what cards are available from this turn's stack?

   turn-get-cards-from-stack : turn/c int -> (listof card/c)
   ;; take a bunch of cards from the stack during this turn 

   turn-can-attack?          : turn/c alliance/c 
                               -> 
                              (listof squadron/c)
   ;; which players/bombers can you attack in this turn 
   ;; given an fighter squadron belonging to an alliance?

;; Turn-to-Administrator INTERFACE

   create-turn               : string? 
                               deck/c 
                               stack/c 
                               (listof squadron/c) 
                               -> 
                               turn/c
   ;; create a turn that assumes the player isn't cheating
   
   turn-end                  : turn/c -> from/c
   ;; did the turn use the top-most card on the 
   ;; deck or some number of stack cards
where the result of a call to turn-end is represented via the following data:


             +--------------------+           
             | From    ABSTRACT   |           
             +--------------------+           
                      |                       
                     / \                  
                     ---                  
                      |                   
          ---------------------           
          |                   |
// how many cards        // player took one 
// were taken?           // card from deck 
+------------------+     +------------------+
| FromStack        |     | FromDeck         |
+------------------+     +------------------+
| int n            |     +------------------+ 
+------------------+     


Task 2: [POINTS: 20] Implement a Squadron Scramble player. In principle, such a player can pursue many different strategies and can even switch strategies during a game. For this assignment, your program must play the game as follows:

  1. unless the deck is empty, it takes one card from the desk or a random number of cards from the stack;
  2. it forms as many complete fighter squadrons (using wild cards where needed) to attack as many bomber squadrons as possible;
  3. it discard as many complete remaining squadrons as possible; and
  4. it returns a card.
Player Interface:

   create            : string? -> player/c
   ;; create a player with a (unique) name

   player-name       : player/c -> string?
   ;; request name from player 
 
   player-hand       : player/c -> hand?
   ;; ask a player for its hand 

   player-first-hand : player/c (listof card/c) -> any
   ;; hand this player the first N cards 

   player-take-turn  : player/c turn/c -> done?
   ;; grant this player a turn
where the result of a call to take-turn is represented via the following data:


             +--------------------+           
             | Done    ABSTRACT   |           +-------------------+
             +--------------------+           | Attack            |      
             | Listof[Attack] a   |---------->+-------------------+
             | Listof[Squadron] d |           | Squadron fighters |
             +--------------------+           | Squadron bombers  |
                      |                       +-------------------+
                     / \                  
                     ---                  
                      |                   
          ---------------------           
          |                   |
 // normal end           // end of player's cards (at most 1 on hand)
+------------------+     +------------------+
| Ret              |     | End              |
+------------------+     +------------------+
| Card r           |     | Card r           | // NULL means no cards left
+------------------+     +------------------+



last updated on Tue Jun 9 22:03:19 EDT 2009generated with PLT Scheme