Due: Friday, March 5th, 2010 11:59pm
Create a program that acts as a Clue player by communicating with a TCP server at a given host and port number, where the protocol now includes suggestions and accusations, but not yet cards. Win this mini-game by accusing the right player with the right weapon in the right room.
Every message from the server to the client now takes two lines. The first one is a message name. The second contains the message data.
The protocol for the game is:
After connection, send a newline-terminated sequence of characters that identifiers your player.
Receive back a hello message whose data is an integer between 0 and 5 to indicate which token the player controls (e.g., 0 for Scarlet).
Receive a turn message whose data is a board state as in HW 3.
roll – The server will response with a rolled message whose data is an integer in 2 to 12.
Send back a destination as an open parenthesis, a number or an uppercase room letter, a space, another number or V, and a closing parenthesis followed by a newline.
If the destination is a room that your player has just entered:
no-roll – The server will response with a rolled message whose data is 0.
Continue after this message in the same way as above for roll.
accuse – The server will respond with an accuse message whose data is simply ?.
Send back an accusation in the same format as a sugegstion.
If the accusation is correct, the game is over, and the server will not respond.
If the accusation is incorrect, the server will respond with a wrong message whose data is !, and no further turn messages will be sent to the player.
This protocol has the property that the message type sent by a server is always predictable. The message names like turn serve only for debugging and sanity checks.
For experimenting, you can use the server provided in server-2.zip, which includes “random” and “sensible” players, both of which track suggestion responses in the obvious way.
Finally, build a client that works for the full Clue game:
Connect and send a name as before.
Receive back a hello message whose data is an open parenthesis, an integer between 0 and 5 to indicate which token the player controls (e.g., 0 for Scarlet), a space another open parenthesis, three space-separated tokens for cards, and two closing parentheses. Each card token can be either a number between 0 and 5 (representing a player), a weapon name, or a room letter. Since they represent cards, each token will be distinct.
For example,
(0 (rope 3 C))corresponds to playing Scarlet with the cards for the rope, Green, and conservatory. Of course, the cards dealt to a player are not necessarily from different categories; they might all be room cards, for example.
For each player that precedes yours in a round, receive a moved message. The data will be
If the last element of the data matches your player's number, then you must respond with a token for one of your cards that disproves the suggestion. Otherwise, the moved message is just a notification of what happened on the player's turn.
The server knows all the cards that it dealt to the players, so it knows which player must disprove a suggestion, and it checks that the player's response to a moved message is legal. For example, as a message to the Green player,
(((U V) (24 17) (15 0) (10 0) (0 6) (U S)) 0 (5 rope U) 3)indicates that Scarlet moved to the lounge and accused Plum with the rope in the lounge; Green must repond with either 5, rope, or U, where one or more of those are definitely (as determined by the server) among Green's cards. The same message to Mustard is simply a notification of what happened – without revealing which card Green used to disprove Scarlet's suggestion.
Receive a turn message and respond to it as in the mini-game above. The only difference is that a counter message with - in response to a suggestion merely means that no other player disproved the suggestion; the suggestion isn't right if the player can disprove its own suggestion using its own cards.
Revision: A counter message from the server has the following revised form, so that a player knows which other player (if any) disproved the suggestion: an open parenthesis, an element of the suggestion (i.e., a player number, weapon name, or room leter) or -, a space, a player number who provided the disproving element or - if the suggestion was not disproved, and a closing parenthesis.
For each player that follows yours in a round, receive a moved message, just as for players that precede yours.
As before, the message type sent by a server with this protocol is always predictable.
For experimenting, you can use the server provided in server-3.1.zip (or server-3.zip for the unrevised protocol). In additon to the “random” and “sensible” players, the provided players include a “leech” player that is activated with -l. The “leech” player does not track its own information, and instead just watches for suggestions that were not disproven, which it immediately uses as an accusation. Since the “sensible” player never bluffs, it is likely to be defeated by the “leech” player.
Last update: Wednesday, March 5th, 2014mflatt@cs.utah.edu |