CSPP 51090 & CMSC 22001: Software Construction Assignment 8: Networking | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Due: November 30, 2004 @ 5pm | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Extend your player interface slightly so that the result of startGame is a string that names your player. [1pt] Design a new server infrastructure that simulates the administrator for a remote player. This should be a program that listens to the network, interprets the data, consults one of your existing players for the actual strategy and then sends the results back over the network. [5pts] Design a new player that accepts its strategy from a remote site, vita tcp/ip. [4pts] For now, test your new system on a local machine. Use port 8000 to communicate via TCP. Each interaction across the network consists of a pair of messages, one in each direction. The content of the messages is goverend by the method type specifications in the Player interface. The sequence of the messages is governed by the sequence contract given in assignment 5.
This is the specification for the data that passes over the network connection:
Things in the purple fixed width font are literal characters that pass across the network, things in green italics refer to other parts of the specification, and things in orange are meta notation about the spec. The ellipses that appear inside tags indicate repetitions: the element just before the ellipses can appear any number of times (including zero times). The ellipses in the number non-terminal indicates that all natural numbers are okay. Each message must be terminated by a newline character and there must not be any other newlines in messages (altho whitespace is otherwise insignificant, except that it separates tokens). The indicies for the main ring of the board start in the central square on the bottom of the board, with zero and continue around counter-clockwise (the directions the pawns travel). Accordingly, green's start square (on the main ring) is at position 5, and green enters the home row from position 0. Similarly, red enters at 22 and exits at 17. The indicies for the home rows start at 0 and continue to 6. This does not includes the purple squares at the beginning of the home row, that square is considered to be on the main ring. On the board, the home row squares are colored according to the color of the pieces (blue's home row is the blue squares, etc).
Here are two example boards with their XML representations next to them: <do-move> <board> <start> <pawn> <color> yellow </color> <id> 3 </id> </pawn> <pawn> <color> yellow </color> <id> 2 </id> </pawn> <pawn> <color> yellow </color> <id> 1 </id> </pawn> <pawn> <color> yellow </color> <id> 0 </id> </pawn> <pawn> <color> red </color> <id> 3 </id> </pawn> <pawn> <color> red </color> <id> 2 </id> </pawn> <pawn> <color> red </color> <id> 1 </id> </pawn> <pawn> <color> red </color> <id> 0 </id> </pawn> <pawn> <color> green </color> <id> 3 </id> </pawn> <pawn> <color> green </color> <id> 2 </id> </pawn> <pawn> <color> green </color> <id> 1 </id> </pawn> <pawn> <color> green </color> <id> 0 </id> </pawn> <pawn> <color> blue </color> <id> 3 </id> </pawn> <pawn> <color> blue </color> <id> 2 </id> </pawn> <pawn> <color> blue </color> <id> 1 </id> </pawn> <pawn> <color> blue </color> <id> 0 </id> </pawn> </start> <main> </main> <home-rows> </home-rows> <home> </home> </board> <dice> <die> 5 </die> <die> 3 </die> </dice> </do-move> and this is the one of the legal responses: <moves> <enter-piece> <pawn> <color> green </color> <id> 0 </id> </pawn> </enter-piece> <move-piece-main> <pawn> <color> green </color> <id> 0 </id> </pawn> <start> 5 </start> <distance> 3 </distance> </move-piece-main> </moves> Overall Hints First, develop the programs that can translate method calls into text messages and text messages into method calls (test the parsing!). Second, wire in your existing code and test each half independently by simulating messages from the other half for simple interactions. Finally, wire everything together and play some games. Parsing Hints There are two options for parsing. First, find a XML parser for your language of choice and use it (this approach can be tricky, since most of the XML libraries I've seen are very heavyweight). Second, you can write your own parser. The protocol only calls for a simple subset of the XML language. There are no dtds required. There are no attributes in the tags. Whitespace is only significant as a delimiter (and inside a name). All of this should make rolling your own special-purpose parser much easier. Be sure to organize your parser as a separate library, so when you find bugs it will be easy to add test cases. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CSPP 51090 & CMSC 22001: Software Construction |