Documentation
¶
Overview ¶
Package chesspairing provides chess tournament pairing, scoring, and tiebreaking engines in pure Go. It implements FIDE-approved Swiss pairing systems (Dutch C.04.3, Burstein C.04.4.2, Dubov C.04.4.1, Lim C.04.4.3, Double-Swiss C.04.5, and Team Swiss C.04.6), Keizer pairing, and round-robin pairing, along with standard, Keizer, and football scoring systems and 25 tiebreaker algorithms.
Engines operate on in-memory data structures (TournamentState, PlayerEntry, RoundData) and have no I/O, database, or network dependencies. They are safe for concurrent use when each goroutine supplies its own TournamentState.
Context: all engine interface methods accept context.Context as their first parameter for API compatibility with service layers. However, since all computation is CPU-bound and in-memory (no I/O, no network), the context is not currently checked for cancellation. Callers should still pass a context for forward compatibility.
Index ¶
- func BoolPtr(v bool) *bool
- func DefaultTiebreakers(system PairingSystem) []string
- func Float64Ptr(v float64) *float64
- func GetBool(m map[string]any, key string) (bool, bool)
- func GetFloat64(m map[string]any, key string) (float64, bool)
- func GetInt(m map[string]any, key string) (int, bool)
- func GetString(m map[string]any, key string) (string, bool)
- func IntPtr(v int) *int
- func StringPtr(v string) *string
- type ByeEntry
- type ByeType
- type GameData
- type GamePairing
- type GameResult
- type NamedValue
- type Pairer
- type PairingConfig
- type PairingResult
- type PairingSystem
- type PlayerEntry
- type PlayerScore
- type ResultContext
- type RoundData
- type Scorer
- type ScoringConfig
- type ScoringSystem
- type Standing
- type TieBreakValue
- type TieBreaker
- type TournamentInfo
- type TournamentState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultTiebreakers ¶
func DefaultTiebreakers(system PairingSystem) []string
DefaultTiebreakers returns the FIDE-recommended tiebreaker order for the given pairing system.
func Float64Ptr ¶
Float64Ptr returns a pointer to v. Used by options packages to set pointer-nil-pattern fields.
func GetBool ¶
GetBool extracts a bool from a map. Returns (false, false) if the key is missing or has an incompatible type.
func GetFloat64 ¶
GetFloat64 extracts a float64 from a map, handling float64, int, and int64 value types. Returns (0, false) if the key is missing or has an incompatible type.
func GetInt ¶
GetInt extracts an int from a map, handling int, int64, and float64 value types. Returns (0, false) if the key is missing or has an incompatible type.
Types ¶
type ByeType ¶
type ByeType int
ByeType classifies how a bye is scored.
const ( ByePAB ByeType = iota // Pairing-Allocated Bye (full point, TRF "F") ByeHalf // Half-point bye (TRF "H") ByeZero // Zero-point bye (TRF "Z") ByeAbsent // Absent/unpaired, unexcused (TRF "U") ByeExcused // Excused absence (notified in advance) ByeClubCommitment // Club commitment (absent for interclub team duty) )
type GameData ¶
type GameData struct {
WhiteID string
BlackID string
Result GameResult
IsForfeit bool
}
GameData is a single game result for engine consumption.
type GamePairing ¶
GamePairing is a single pairing assignment for a round.
type GameResult ¶
type GameResult string
GameResult represents the outcome of a chess game.
const ( ResultWhiteWins GameResult = "1-0" ResultBlackWins GameResult = "0-1" ResultDraw GameResult = "0.5-0.5" ResultPending GameResult = "*" ResultForfeitWhiteWins GameResult = "1-0f" ResultForfeitBlackWins GameResult = "0-1f" ResultDoubleForfeit GameResult = "0-0f" )
func (GameResult) IsDoubleForfeit ¶
func (gr GameResult) IsDoubleForfeit() bool
IsDoubleForfeit returns true if both players forfeited. Double-forfeit games are excluded from both pairing and scoring — the game never happened.
func (GameResult) IsForfeit ¶
func (gr GameResult) IsForfeit() bool
IsForfeit returns true if the result is a forfeit (single or double). Forfeit games are excluded from pairing history — players can be re-paired within the same period.
func (GameResult) IsRecordable ¶
func (gr GameResult) IsRecordable() bool
IsRecordable returns true if the game result is a valid result that can be recorded by a user. ResultPending ("*") is valid but not recordable — it is the initial state set by the system when a game is created.
func (GameResult) IsValid ¶
func (gr GameResult) IsValid() bool
IsValid returns true if the game result is a recognized value.
type NamedValue ¶
type NamedValue struct {
ID string `json:"id"`
Name string `json:"name"`
Value float64 `json:"value"`
}
NamedValue pairs a tiebreaker identifier with its computed value.
type Pairer ¶
type Pairer interface {
Pair(ctx context.Context, state *TournamentState) (*PairingResult, error)
}
Pairer generates pairings for a round given tournament state.
type PairingConfig ¶
type PairingConfig struct {
System PairingSystem
Options map[string]any
}
PairingConfig holds per-period pairing settings.
type PairingResult ¶
type PairingResult struct {
Pairings []GamePairing
Byes []ByeEntry
Notes []string
}
PairingResult is returned by a Pairer.
type PairingSystem ¶
type PairingSystem string
PairingSystem identifies which pairing algorithm to use.
const ( PairingDutch PairingSystem = "dutch" PairingBurstein PairingSystem = "burstein" PairingDubov PairingSystem = "dubov" PairingLim PairingSystem = "lim" PairingDoubleSwiss PairingSystem = "doubleswiss" PairingTeam PairingSystem = "team" PairingKeizer PairingSystem = "keizer" PairingRoundRobin PairingSystem = "roundrobin" )
func (PairingSystem) IsValid ¶
func (p PairingSystem) IsValid() bool
IsValid returns true if the pairing system is a recognized value.
type PlayerEntry ¶
type PlayerEntry struct {
ID string
DisplayName string
Rating int
Active bool
Federation string // FIDE federation code (e.g. "NED", "USA", "IND"). Empty if unknown.
FideID string // FIDE player ID number. Empty if unknown.
Title string // FIDE title code (GM, IM, FM, WGM, WIM, WFM, CM, WCM). Empty if untitled.
Sex string // "m" or "w". Empty if unknown.
BirthDate string // Birth date as YYYY/MM/DD. Empty if unknown.
JoinedRound int // Round number the player joined. 0 or 1 means original player (joined from the start).
}
PlayerEntry represents a player for engine purposes.
type PlayerScore ¶
PlayerScore holds a player's calculated score from the scoring engine.
type ResultContext ¶
type ResultContext struct {
OpponentRank int
OpponentValueNumber int
PlayerRank int
PlayerValueNumber int
IsBye bool
IsAbsent bool
IsForfeit bool
}
ResultContext provides additional information needed by scoring systems when calculating points for a specific game result.
type Scorer ¶
type Scorer interface {
Score(ctx context.Context, state *TournamentState) ([]PlayerScore, error)
PointsForResult(result GameResult, rctx ResultContext) float64
}
Scorer calculates standings from game results.
type ScoringConfig ¶
type ScoringConfig struct {
System ScoringSystem
Tiebreakers []string
Options map[string]any
}
ScoringConfig holds tournament-wide scoring settings.
type ScoringSystem ¶
type ScoringSystem string
ScoringSystem identifies which scoring algorithm to use.
const ( ScoringStandard ScoringSystem = "standard" ScoringKeizer ScoringSystem = "keizer" ScoringFootball ScoringSystem = "football" )
func (ScoringSystem) IsValid ¶
func (s ScoringSystem) IsValid() bool
IsValid returns true if the scoring system is a recognized value.
type Standing ¶
type Standing struct {
Rank int `json:"rank"`
PlayerID string `json:"playerId"`
DisplayName string `json:"displayName"`
Score float64 `json:"score"`
TieBreakers []NamedValue `json:"tieBreakers"`
GamesPlayed int `json:"gamesPlayed"`
Wins int `json:"wins"`
Draws int `json:"draws"`
Losses int `json:"losses"`
}
Standing is the final ranked output combining score and tiebreakers.
type TieBreakValue ¶
TieBreakValue is a single tiebreak computation for one player.
type TieBreaker ¶
type TieBreaker interface {
ID() string
Name() string
Compute(ctx context.Context, state *TournamentState, scores []PlayerScore) ([]TieBreakValue, error)
}
TieBreaker computes a single tiebreak value for each player.
type TournamentInfo ¶
type TournamentInfo struct {
Name string
City string
Federation string // Organizing federation code
StartDate string // YYYY/MM/DD
EndDate string // YYYY/MM/DD
ChiefArbiter string
DeputyArbiter string
TimeControl string // Allotted time description
RoundDates []string // YYYY/MM/DD per round
}
TournamentInfo holds tournament metadata for display and TRF round-trip fidelity. Engines ignore this struct; it is populated from TRF header lines and written back when serializing to TRF.
type TournamentState ¶
type TournamentState struct {
Players []PlayerEntry
Rounds []RoundData
CurrentRound int
PairingConfig PairingConfig
ScoringConfig ScoringConfig
Info TournamentInfo // Tournament metadata. Zero value if not set.
}
TournamentState is the read-only snapshot of a tournament passed to engines. The caller constructs this from their data source before calling any engine method. Engines never perform I/O directly.
func (*TournamentState) Validate ¶
func (s *TournamentState) Validate() error
Validate checks structural invariants of the tournament state. Returns an error describing the first problem found, or nil if valid.
Directories
¶
| Path | Synopsis |
|---|---|
|
algorithm
|
|
|
blossom
Package blossom implements Edmonds' maximum weight matching algorithm for general graphs.
|
Package blossom implements Edmonds' maximum weight matching algorithm for general graphs. |
|
varma
Package varma implements the Varma Tables pre-processing number assignment scheme for round-robin chess tournaments (FIDE C.05 Annex 2).
|
Package varma implements the Varma Tables pre-processing number assignment scheme for round-robin chess tournaments (FIDE C.05 Annex 2). |
|
cmd
|
|
|
chesspairing
command
cmd/chesspairing/check.go
|
cmd/chesspairing/check.go |
|
pairing
|
|
|
burstein
Package burstein implements the Burstein Swiss pairing system (C.04.4.2).
|
Package burstein implements the Burstein Swiss pairing system (C.04.4.2). |
|
doubleswiss
Package doubleswiss implements the FIDE Double-Swiss pairing system (C.04.5).
|
Package doubleswiss implements the FIDE Double-Swiss pairing system (C.04.5). |
|
dubov
pairing/dubov/dubov.go
|
pairing/dubov/dubov.go |
|
dutch
Package dutch implements the FIDE Dutch Swiss pairing system (C.04.3).
|
Package dutch implements the FIDE Dutch Swiss pairing system (C.04.3). |
|
keizer
Package keizer implements Keizer-style pairing for chess tournaments.
|
Package keizer implements Keizer-style pairing for chess tournaments. |
|
lexswiss
Package lexswiss provides shared data structures and algorithms for lexicographic Swiss pairing systems.
|
Package lexswiss provides shared data structures and algorithms for lexicographic Swiss pairing systems. |
|
lim
Package lim implements the Lim Swiss pairing system (C.04.4.3).
|
Package lim implements the Lim Swiss pairing system (C.04.4.3). |
|
roundrobin
Package roundrobin implements round-robin pairing for chess tournaments.
|
Package roundrobin implements round-robin pairing for chess tournaments. |
|
swisslib
Package swisslib provides shared data structures and algorithms for Swiss pairing engines.
|
Package swisslib provides shared data structures and algorithms for Swiss pairing engines. |
|
team
Package team implements the FIDE Swiss Team Pairing System (C.04.6).
|
Package team implements the FIDE Swiss Team Pairing System (C.04.6). |
|
scoring
|
|
|
football
Package football implements football-style scoring (3-1-0) for chess tournaments.
|
Package football implements football-style scoring (3-1-0) for chess tournaments. |
|
keizer
Package keizer implements Keizer point scoring for chess tournaments.
|
Package keizer implements Keizer point scoring for chess tournaments. |
|
standard
Package standard implements standard chess scoring (1-½-0).
|
Package standard implements standard chess scoring (1-½-0). |
|
Package tiebreaker implements chess tournament tiebreakers.
|
Package tiebreaker implements chess tournament tiebreakers. |
|
Package trf implements reading and writing of TRF16 (FIDE Tournament Report File) documents.
|
Package trf implements reading and writing of TRF16 (FIDE Tournament Report File) documents. |