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:
@@ -0,0 +1,26 @@
|
||||
## How a server runs its matches: lobby size, timers and team size. Defaults come from
|
||||
## Tuning; a server or test changes them per instance.
|
||||
class_name MatchRules
|
||||
extends RefCounted
|
||||
|
||||
## The most participants in one match, bots included.
|
||||
var max_players: int = Tuning.SOLO_PLAYERS
|
||||
## The lobby counts down once this many participants have joined.
|
||||
var min_players: int = Tuning.MATCH_MIN_PLAYERS
|
||||
## Players on a team. 1 is solo.
|
||||
var team_size: int = 1
|
||||
## With enough players, the lobby waits this long for more before counting down. A
|
||||
## full lobby counts down at once.
|
||||
var lobby_ticks: int = roundi(Tuning.MATCH_LOBBY_SECONDS * Tuning.TICK_RATE_HZ)
|
||||
var countdown_ticks: int = roundi(Tuning.MATCH_COUNTDOWN_SECONDS * Tuning.TICK_RATE_HZ)
|
||||
var results_ticks: int = roundi(Tuning.MATCH_RESULTS_SECONDS * Tuning.TICK_RATE_HZ)
|
||||
## Fill empty places with bots when the match starts.
|
||||
var fill_with_bots: bool = true
|
||||
|
||||
|
||||
## Rules for a server that skips the lobby: the match starts on the first tick.
|
||||
static func immediate() -> MatchRules:
|
||||
var rules: MatchRules = MatchRules.new()
|
||||
rules.lobby_ticks = 0
|
||||
rules.countdown_ticks = 0
|
||||
return rules
|
||||
Reference in New Issue
Block a user