Battleship Protocol - Zomis/Server GitHub Wiki
Battleship Game Start
After the server has sent a NEWG
message to the clients, it will immediately send information about the current Battleship game.
From server:
CONF id mapWidth mapHeight ship-name width height ship-name width height ship-name width height...
For example:
CONF 0 10 10 Air_Carrier 5 1 Battleship 4 1 Submarine 3 1 Submarine 3 1 Patrol 2 1
This is the information about the different types of ships in the game. In this example, there is the following ships:
- 1 x "Air_Carrier" with size 5x1
- 1 x "Battleship" with size 4x1
- 2 x "Submarine" with size 3x1
- 1 x "Patrol" with size 2x1
Then it is up to you to place these ships and send the placement back:
Send:
MOVE id SHIP ship-name width height x y ship-name width height x y ship-name width height x y...
For example:
MOVE 0 SHIP Air_Carrier 5 1 4 0 Battleship 4 1 5 3 Submarine 1 3 2 0 Submarine 4 1 0 7 Patrol 1 2 7 7
This will place the ship as follows:
xxxxxxxxxxxxxxx (to be added)
The server will then confirm your placement with MOVE gameid OK
Battleship Play
When both players have placed their ships, or the server decides that it is the other players turn to play, it sends the following:
From server: MOVE gameid TURN playerindex
If the playerindex
matches your playerindex (received in the NEWG
message), then it is your turn to play.
Playing at your opponents turn will get you disqualified. Be sure that it is your turn before you play.
Send: MOVE gameid PLAY x y
For example: MOVE 1 PLAY 4 2
- in gameid 1, make a move at position (4, 2)
Response: MOVE gameid PLAY playerindex x y HIT
or MOVE id PLAY playerindex x y MISS