Star Gambit Computer Player SDK
sg-sdk SGN.md
2.5 kB · 66 lines
Markdown
at main

Star Gambit Notation (SGN) #

SGN is the text format for Star Gambit actions and game records. A whole game is just a whitespace-separated sequence of action tokens (split on spaces, tabs, or newlines), replayed in order through the engine to reconstruct the position.

The five tokens #

Every token is one of these forms. Each numeric field is a 0-based index, not a coordinate.

Form Meaning Fields
<kind>@<placement> Deploy a reserve ship kind = ship kind index (config order); placement = which legal placement slot
<unit>+<move> Move a unit unit = unit id; move = index into that ship kind's move table
<unit>*<attack> Fire a gun unit = unit id; attack = index into that ship kind's ray-attack table
END:<time> End your turn time = timestamp in ms (see note)
<loser>=<reason> / …==… Game over loser = 0 or 1; reason = loss code. A token containing == is a draw

Unit ids #

A unit id is the unit's position in the engine's unit list, assigned in the order ships are placed and shared across both players. Ids are never reused; destroyed units keep their id (you simply won't find legal moves/attacks for them).

Placement rule #

Only END may follow a placement in the same turn; once you deploy a ship, the turn is over.

Attacks #

A gun's attack index selects a ray from the ship kind's attack table; the ray hits the first enemy ship along it for 2 damage at the nearest hex, 1 further out. Each gun may fire at most once per turn, and an attack must hit an enemy to be legal.

Ending a turn #

The engine validates END:<time> with a real timestamp, but over the wire the com sends a bare END and the server/runner stamps the time itself. That's why legal_actions() emits "END" while records on disk show END:<ms>.

Game-end reasons #

<loser>=<reason> records that player <loser> (0 or 1) lost, for one of:

Code Reason
FF Forfeit
T Ran out of time
P Lost their portal
W Lost all ships
N No legal options left

A draw (threefold repetition) is any token containing ==, e.g. 0==1.

Example #

0@2 END:1500 0@2 END:3100 3+1 END:5200 3*0 END:6800 1=FF

Both players deploy a ship (0@2, each followed by END), then player 0 moves unit 3 (3+1) and later fires its first gun (3*0), ending with player 1's forfeit (1=FF).