Skip to content

Repository files navigation

Koya

npm Coverage License: MIT Spec

Koya computes the Koya tiebreak — a FIDE-defined method for breaking tied scores in round-robin (all-play-all) chess tournaments (section 9.2). TypeScript, zero runtime dependencies.

Installation

npm install @echecs/koya

Quick Start

import { koya, tiebreak } from '@echecs/koya';
import type { Game, GameKind, Player, Result } from '@echecs/koya';

// games[n] = round n+1; Game has no `round` field
const games: Game[][] = [
  [{ black: 'B', result: 1, white: 'A' }], // round 1
  [{ black: 'C', result: 0.5, white: 'A' }], // round 2
  [{ black: 'A', result: 0, white: 'D' }], // round 3
  // Unplayed rounds use kind to classify the bye type
  [{ black: '', kind: 'half-bye', result: 0.5, white: 'A' }], // round 4
];

const score = koya('A', games);
// Returns points scored against opponents who achieved >= 50% of the maximum score

API

koya(player, games)

FIDE section 9.2. Returns the total points player scored against opponents who reached at least 50% of the tournament's maximum possible score. Round-robin format only.

Byes (unplayed rounds) count toward neither the 50% threshold nor the score sum. Array position sets the round: games[0] = round 1, games[1] = round 2, etc. The optional kind?: GameKind field on Game classifies unplayed rounds.

koya(player: string, games: Game[][]): number

tiebreak is an alias for koya for use in tiebreak pipelines.

/limit-m1

FIDE C.07 sections 9.2 + 14.5. Koya with the threshold lowered to 50% − ½: opponents qualify when they scored strictly more than half the rounds minus one half point.

import { koyaLimitM1, tiebreak } from '@echecs/koya/limit-m1';

/limit-m2

FIDE C.07 sections 9.2 + 14.5. Koya with the threshold lowered to 50% − 1: opponents qualify when they scored strictly more than half the rounds minus one point.

import { koyaLimitM2, tiebreak } from '@echecs/koya/limit-m2';

/limit-p1

FIDE C.07 sections 9.2 + 14.5. Koya with the threshold raised to 50% + ½: opponents qualify when they scored strictly more than half the rounds plus one half point.

import { koyaLimitP1, tiebreak } from '@echecs/koya/limit-p1';

/limit-p2

FIDE C.07 sections 9.2 + 14.5. Koya with the threshold raised to 50% + 1: opponents qualify when they scored strictly more than half the rounds plus one point.

import { koyaLimitP2, tiebreak } from '@echecs/koya/limit-p2';

Exports

// Functions
export { koya, tiebreak } from '@echecs/koya';

// Types
export type { Game, GameKind, Player, Result } from '@echecs/koya';

Each limit variant subpath exports its named function (e.g. koyaLimitP1), a tiebreak alias, and the same Game, GameKind, Player, and Result types.

Contributing

Contributions are welcome. Please open an issue at github.com/echecsjs/koya/issues.

About

Koya tiebreak system for round-robin chess tournaments following FIDE rules. Zero dependencies.

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages