Documentation
¶
Overview ¶
Package team implements the FIDE Swiss Team Pairing System (C.04.6).
The Team Swiss system (approved Oct 2025, effective Feb 2026) pairs teams using lexicographic bracket pairing (Art. 3.6) from the shared pairing/lexswiss package. Each PlayerEntry in TournamentState represents a team.
Key characteristics:
- Configurable primary score: "match" points (default) or "game" points
- Two colour preference types: Type A (simple) and Type B (strong + mild)
- No absolute colour criteria (C8-C10 are quality criteria only)
- C7 and C10 relaxed in last TWO rounds
- 9-step colour allocation (Art. 4)
- Colour determined by first board assignment (Art. 1.6.1)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllocateColor ¶
func AllocateColor(a, b *lexswiss.ParticipantState, prefType ColorPrefType, isLastRound bool, initialColor *string, secondaryScores map[string]float64) (string, string)
AllocateColor decides which team gets White and which gets Black, implementing the 9-step colour allocation algorithm of Art. 4.
Parameters:
- a, b: the two teams in the pairing
- prefType: colour preference type (A, B, or None)
- isLastRound: true if this is the last round (affects Type B mild prefs)
- initialColor: the initial-colour from drawing of lots (Art. 4.1)
- secondaryScores: secondary score map (Art. 4.2.2), nil if not used
Returns (whiteID, blackID).
func BuildCriteriaFunc ¶
func BuildCriteriaFunc(prefType ColorPrefType, isLastTwoRounds bool, isLastRound bool) lexswiss.CriteriaFunc
BuildCriteriaFunc creates a lexswiss.CriteriaFunc that checks Team Swiss quality criteria C8 and C9 for a proposed pair.
C8: Minimise teams whose colour preference is not fulfilled.
Two teams with the same colour preference cannot both be satisfied, so such pairings violate C8.
C9 (Type B only): Minimise teams whose strong colour preference is not
fulfilled. Two teams with the same strong preference violate C9.
C10 (upfloater opponents) is handled at the bracket/upfloater level, not per-pair, so it is not checked here.
Parameters:
- prefType: colour preference type (A, B, or None)
- isLastTwoRounds: true if pairing one of the last two rounds (C7/C10 relaxation)
- isLastRound: true if pairing the last round (affects Type B mild preferences)
Returns nil if colour preferences are disabled (ColorPrefTypeNone).
Types ¶
type ColorPref ¶
type ColorPref int
ColorPref represents a team's colour preference strength and direction.
const ( ColorPrefNone ColorPref = iota // No preference ColorPrefWhite // Type A: simple preference for White ColorPrefBlack // Type A: simple preference for Black ColorPrefStrongWhite // Type B: strong preference for White ColorPrefStrongBlack // Type B: strong preference for Black ColorPrefMildWhite // Type B: mild preference for White ColorPrefMildBlack // Type B: mild preference for Black )
func ComputeColorPreference ¶
func ComputeColorPreference(p *lexswiss.ParticipantState, prefType ColorPrefType, isLastRound bool) ColorPref
ComputeColorPreference calculates a team's colour preference based on its match history, the preference type, and whether this is the last round.
Implements Art. 1.7 of the Team Swiss system:
- Type A (1.7.1): Simple colour preferences (preference for White/Black, or none)
- Type B (1.7.2): Strong and mild colour preferences
- Type None: No colour preferences (always returns ColorPrefNone)
Parameters:
- p: participant state with colour history
- prefType: which colour preference rules to use
- isLastRound: true if pairing the last round (affects Type B mild preferences)
type ColorPrefType ¶
type ColorPrefType int
ColorPrefType identifies which colour preference rules to use.
const ( ColorPrefTypeA ColorPrefType = iota // Simple: preference or none (default) ColorPrefTypeB // Strong + mild + none ColorPrefTypeNone // No colour preferences )
func (ColorPrefType) String ¶
func (t ColorPrefType) String() string
String returns the type name for debugging.
type Options ¶
type Options struct {
// TopSeedColor is the colour determined by drawing of lots before round 1.
// Values: "white" (default initial-colour), "black".
// This is called "initial-colour" in Art. 4.1.
TopSeedColor *string `json:"topSeedColor,omitempty"`
// ForbiddenPairs lists team ID pairs that must not be paired together.
ForbiddenPairs [][]string `json:"forbiddenPairs,omitempty"`
// TotalRounds is the total number of rounds in the tournament.
// Used to determine "last two rounds" for C7/C10 relaxation,
// and "last round" for Type B mild preference calculation.
TotalRounds *int `json:"totalRounds,omitempty"`
// ColorPreferenceType selects which colour preference rules to use.
// Values: "A" (default, Type A simple), "B" (Type B strong+mild),
// "none" (no colour preferences).
// Corresponds to Art. 1.7.
ColorPreferenceType *string `json:"colorPreferenceType,omitempty"`
// PrimaryScore selects which score is used for pairing.
// Values: "match" (default, match points), "game" (game points).
// The other score becomes the "secondary score" used for colour allocation
// (Art. 4.2.2).
// Corresponds to Art. 1.2.
PrimaryScore *string `json:"primaryScore,omitempty"`
}
Options holds Team Swiss-specific pairing configuration. All pointer fields use nil = use default.
func ParseOptions ¶
ParseOptions converts a generic map[string]any into typed Options.
func (Options) WithDefaults ¶
WithDefaults returns a copy of options with defaults applied for nil fields.
type Pairer ¶
type Pairer struct {
// contains filtered or unexported fields
}
Pairer implements the chesspairing.Pairer interface for the Team Swiss system.
func NewFromMap ¶
NewFromMap creates a new Team Swiss pairer from a generic options map.
func (*Pairer) Pair ¶
func (p *Pairer) Pair(_ context.Context, state *chesspairing.TournamentState) (*chesspairing.PairingResult, error)
Pair implements chesspairing.Pairer for the Team Swiss system.