ParlorNet
Turn-based game server for any computer, old or new
Clients | Protocols | Browsers | Telnet programs | Docs | Source

navalcombat/1 (draft)

Two players. Single-step moves (no staged). A hidden-information game: each player places a fleet on their own grid, and the two then take turns firing one shot at the other's grid. The server holds both fleets; a view and the events never show a square of a ship to anyone but its owner until that ship is sunk.

Rulesets (the grid is 10 by 10 in both):

Every ship lies straight, across or down. Options: none; NEW with any game option is refused (ERR BADOPT no options for this game). turn=, vis= and players= are the server's (protocol.md). Planned: salvo=1, a salvo of one shot per ship still afloat each turn; it would add a staged turn (one MOV per shot, then END) and is not part of this version.

Seat 0 fires first. There is no draw: the game ends when one fleet is entirely sunk, or by the shared ends (resign, timeout, abandoned).

Phases

  1. Placing (Q place). Both players place at the same time, each ship in the order of FL (largest first). A player may take back the last ship (undo), remove them all (clear) or have the server place the ships not yet placed at random (random; with the whole fleet placed, random places the whole fleet again). Once the fleet is complete the player sends ready; after that the fleet cannot change. Random placements come from the table's seed, so a game replays.
  2. Shooting (Q shoot) starts when both fleets are ready. One shot per turn, hit or miss; the turn then passes to the other player.
  3. Over (Q over): every ship of one fleet is sunk.

The turn clock: the game starts with TURN 0, so seat 0 is on the clock while placing. When seat 0 is ready and seat 1 is not, TURN 1 puts seat 1 on the clock. When both are ready, TURN 0 starts the shooting with a fresh clock. A player who never places their fleet loses on time like any other.

Static geometry (flag G)

LineMeaning
BRD w hThe grid: BRD 10 10.
FL len len ...The fleet, in placement order: FL 5 4 3 3 2 (classic), FL 4 3 3 2 2 2 1 1 1 1 (batnav).

View lines

What a line shows depends on who asks: the server builds each seat's view (and the watchers' view) from what that viewer may know.

LineMeaning
Q phaseplace, shoot or over.
W seatWhose turn it is; W - when the game is over. While placing, a seat whose fleet is not ready sees its own seat (it has a move to make); others see the first seat still placing (the one on the clock).
RD r0 r11 when that seat's fleet is placed and ready.
B seat y cellsRow y (1-10, from the top) of seat's waters, one character per column a-j: . nothing known (for the owner: open water), o a miss, x a hit, # a square of a sunk ship, and only in the owner's own view s a ship square not hit. Rows that are all . are not sent.
Y len from-toThe viewer's own ships (seated players only, never another seat's), in placement order: Y 5 a1-e1.
N lenWhile placing: the length of the viewer's next ship (absent once the fleet is complete or ready).
K seat len from-toA sunk ship of seat's fleet, for everyone: every square of it has been hit.
L n0 n1Ships afloat per seat (the whole fleet until that seat is ready).
LS seat sqThe last shot: who fired, and where.

The common lines S, M and CLK mean what protocol.md says.

For a watcher, both grids show only shots and sunk ships; no Y or N lines. A seat's view of the other grid is the same as a watcher's. The view's data (JSON for modern clients) carries the same filtered rows, never the state.

The rows are a dense encoding because a grid fills with shots: 20 rows of 17 bytes is the worst case, and an empty grid sends nothing.

Move tokens

CHK of a shot says only whether it may be fired (OK); it never tells hit or miss.

Events

Events go to every player and watcher, so none names a square of a ship that has not been hit:

Size

A full view is about 60 bytes while placing (plus the M list: up to about 140 placements of 6 to 8 bytes for the player placing), and at most about 450 bytes late in the game. Typical event 15-30 bytes.

Notes

This doc on GitHub


 These pages cover every ParlorNet server. | Source code | ParlorNet is free software.