M1: Match state machine

Match (src/sim/match.gd) runs a server's matches back to back: lobby,
countdown, drop, play and results, then a fresh island and the lobby again.
It is stepped once per server tick and has no scene-tree or clock dependency.

- MatchRules holds max and min players, team size, the lobby, countdown and
  results timers (defaults in Tuning.MATCH_*) and whether bots fill empty
  places.
- Participants are server-chosen handles. Joining during a match waits for
  the next; leaving during the drop or play places the leaver as eliminated.
- Placements, winners (last team standing) and events for phase changes,
  joins, leaves, places, match start and end.
- Match 0 uses the server's seed; later matches derive their seed from it and
  their index. The next match's Simulation is built when the lobby opens.
- ServerLoop now drives a Match (immediate rules by default, so the smoke
  match is unchanged: same state hash), rebuilds bots each match, and counts
  server ticks across matches. The headless server logs match events.

Tests: test_match (13) covers every transition, leaving in each phase, an
empty lobby, an empty match, teams, late joiners, and ten consecutive matches
that each start identical to a freshly built simulation. A ServerLoop test
checks the server goes back to the lobby and starts the next match.

Closes #24

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 20:24:00 -05:00
co-authored by Claude Opus 5.5
parent 0013a81658
commit c6f3c19004
11 changed files with 649 additions and 23 deletions
+17
View File
@@ -40,6 +40,23 @@ name, so it can't drift from the game. To change a number, edit that file.
| Solo | 24 players | `SOLO_PLAYERS` |
| Duos | 12 teams of 2 | `DUO_TEAMS`, `DUO_TEAM_SIZE` |
### Match flow
The server runs matches back to back, in [`src/sim/match.gd`](../src/sim/match.gd):
1. **Lobby.** Players join. Once `MATCH_MIN_PLAYERS` are in, it waits
`MATCH_LOBBY_SECONDS` for more, or counts down at once when full.
2. **Countdown.** `MATCH_COUNTDOWN_SECONDS`. If too many leave, it goes back to the lobby.
3. **Drop.** Bots fill the empty places, everyone boards the barge and loot is placed.
4. **Play.** Ends when at most one team has anyone standing.
5. **Results.** Finishing places and the winners stay up for `MATCH_RESULTS_SECONDS`,
then bots leave and the server goes back to the lobby with a new island.
Leaving during the drop or play counts as being eliminated where you stood. Joining
during a match waits in the lobby for the next one. Every timer can be changed per
server through `MatchRules`. Match 0 uses the server's seed; later matches derive theirs
from it, so a whole session can be replayed from one seed.
Bots fill empty slots. Offline play is a local server filled with bots, the same game
code as online play. A downed duo partner can be revived, within `REVIVE_SECONDS`.