Client protocol
The protocol is all based on character strings sent to the server, and received from the server. On startup, each player is sent a name request (name?) to which they must respond with nameis followed by any name. They are then sent a list of other players to which they can respond with choose followed by a name, or none, which means wait for another player. If a player is chosen, that player receives a connect? offer, to which they may respond with yes or no. No gets the list of other players again, and the offerer gets an empty string message (just used a s an an acknowledge message) to which a new reponse may be given (or quit). If a yes is returned, then play begins by one player getting a guess? message. (Note that you will not receive an offer until you respond to every outstanding list message). The response to guess? must be guess followed by two numbers between 1 and 10, for the guessed grid position. Play then alternates with hit or miss followed by grid coordinates until one player declares a loss (all ships sunk) with a quit message, in which case, the connection to the server is broken, or new, in which case the list of other players is sent again. (quit may also be sent during the offer/response sequence). Any player may quit at any time.
|
state |
IN |
OUT |
state |
|
0 |
name? |
nameis <name> |
1 |
|
1 |
list ... <name> … |
choose <name> |
2 |
|
|
|
choose none |
1 |
|
quit |
- |
||
|
1 |
connect? <name> |
yes |
2 |
|
|
|
no |
1 |
|
|
|
quit |
- |
|
1 |
quit? |
quit |
- |
|
|
|
new |
1 |
|
1 |
guess? |
guess <x> < y> |
2 |
|
|
|
quit |
- |
|
2 |
<report>* |
<report>* |
2 |
|
|
|
quit |
- |
|
2 |
quit? |
new |
1 |
|
|
|
quit |
- |
|
2 |
guess? |
guess <x> <y> |
2 |
*<report> is:
hit <x> <y> or
miss <x> <y> or
sunk <ship> <x> <y>
where <ship> is one of A, B, C, D or S for aircraft carrier, battleship, cruiser, destroyer or submarine, and <x> and <y> are natural numbers.