1 / 15

GBK Programming 2 2009-10

GBK Programming 2 2009-10. Jordan Johnson. Today’s plan. Greeting Networking and the Sea Battle game Clean-up. Multi-player sea battle: Networking. player 2. server. player 1. Requirements: Player program ( client ) “Game master” program ( server ) Protocol to govern communications.

aradia
Download Presentation

GBK Programming 2 2009-10

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GBK Programming 22009-10 Jordan Johnson

  2. Today’s plan Greeting Networking and the Sea Battle game Clean-up

  3. Multi-player sea battle:Networking player 2 server player 1 • Requirements: • Player program (client) • “Game master” program (server) • Protocol to govern communications

  4. Multi-player sea battle: Example Protocol “Give me a ship of length 5.” player 2 (place 5) server player 1 • Placing ships: • Server requests a ship • Player places a ship • Repeat until all ships are placed.

  5. Multi-player sea battle: Example Protocol player 2 ((1 1) (2 1) (3 1) (4 1) (5 1)) server player 1 “Here it is: (1,1), (2,1), ...” • Placing ships: • Server requests a ship • Player places a ship • Repeat until all ships are placed.

  6. Multi-player sea battle:Example Protocol “Give me a ship of length 4.” player 2 (place 4) server player 1 ...and so on... • Placing ships: • Server requests a ship • Player places a ship • Repeat until all ships are placed.

  7. Battle Protocol: Placing Ships • Summary of messages required: • Server  Client: (place N), where N  {2,3,4,5} • Client  Server: listof[coord-pair] • where a coord-pair is a list of two coords, • and a coord is a nat[<20]. • Server  Client: • All ships are placed? ‘your-turn OR ‘enemy-turn • Player’s ships are all placed? ‘ok • Player sent a bogus ship? (try-again N) • Ships left to place? Back to...(place N) • The players are mostly independent.

  8. Battle protocol: Shooting Represents the cell a player is shooting at Responses to shots (if a ship was sunk, length was its length) coord = nat[<20] length = int[2..5] “win” messages mean the player’s last shot won the game.

  9. Implementing the Universe(Server-side data) • Data required for the placement phase:

  10. Implementing the Universe (Server-side data) • Data required for the battle phase:

  11. Data Definitions A pre-battle is a (make-pre-battle iworldiworld listof[len] listof[len] board board) (define-struct pre-battle (p1 p2 len1* len2* bd1 bd2)) representing the phase of the game where p1 and p2 are connected, have placed the ships on their boards bd1 & bd2, and have yet to place ships of the lengths specified in len1* and len2*. • Data definitions for the universe (server): A universe is either • empty, or • an iworld, or • a pre-battle, or • a battle.

  12. Data Definitions ; A battle is a ; (make-battle iworldiworld; board board ; status) (define-struct pre-battle (p1 p2 bd1 bd2 status)) ; where status is either ; ‘p1-turn or ‘p2-turn or ; ‘game-over. ; This represents a state in the ; turn-based portion of the ; game: bd1 and bd2 store the ; current state of the ships; ; status tells whose turn it is ; (or whether the game’s ended). • Data definitions for the universe (server): A universe is either • empty, or • an iworld, or • a pre-battle, or • a battle.

  13. To-do List (for the universe): • on-new handler: • hookup : universe world  bundle • on-disconnect handler: • hangup : universe world  bundle • on-msg handler: • receive : universe world  bundle • Add helper functions as needed.

  14. Reminders Write out your templates. In the handlers, decide what kind of universe you have, and call a helper function for the appropriate kind. Use helper functions to process lists. Write test cases before functions.

  15. Clean-up • Before you leave, please . . . • Log out. • Push in your chair. • Make sure you’ve got everything. • Make sure all trash ends up in the trash can.

More Related