# FairPair tools: pairings and tie-break checker, random tournament generator This is the English guide to the two command-line tools that FairPair makes available to everyone, free of charge, as the FIDE Handbook requires of a tournament handler program (C.02.03, Articles 7.1.3 c, 7.2.3 and 7.2.4): | Tool | What it does | |---|---| | `fpc.py` — the **checker** (PTC) | Reads a tournament file (TRF), pairs every round again and compares the result with the pairings recorded in the file; then recomputes the standings and compares them with the points and ranks recorded in the file. | | `rtg.py` — the **generator** (RTG) | Produces fully played random Swiss tournaments as tournament files. | Both tools pair with FairPair's own pairing engine: the FIDE (Dutch) System, C.04.3, in the version effective from 1 February 2026. Tie-breaks follow C.07 in the version effective from 1 March 2026. The tools are a part of the program, not an addition to it. The files in this package — the two tools and the modules they compute with (`engine.py`, `dutch.py`, `paarung_gewichtet.py`, `wertung.py`) — are the files the FairPair website itself pairs and ranks with; the website builds the package from its own program folder. How to verify that is described under “Version and integrity”. The guide to the website itself is its help page (`/hilfe.html`, in English with `?lang=en`). FairPair is not a FIDE-endorsed program. The tools implement the published rules; they have not been approved by FIDE. ## Requirements * Python 3.9 or later. Nothing else: the tools use the Python standard library only. No installation, no database, no web server. * The files of the package in one folder, as they are unpacked. * Java is needed only for the option `--engine javafo` (pairing by the rules valid until 31 January 2026, with JaVaFo 2.2). JaVaFo is not part of the package; put `javafo.jar` next to the files or let the environment variable `JAVAFO_JAR` point to it. All commands below are run in the folder of the package. Where the Python interpreter is called `python` or `py` (Windows), use that instead of `python3`. ## A first run Generate twenty tournaments and check them: ```bash python3 rtg.py --count 20 --seed 2026 --folder rtg-out python3 fpc.py rtg-out/*.trf --short ``` The generator prints one line per file, for example ``` rtg-out/rtg-0001.trf 28 players, 9 rounds, 117 games, 4 PAB, 7 H-bye, 4 Z-bye, 3 F-bye, 2 forfeit(s), 1 unusual result(s), ranked by PTS,BH/C1,BH,SB ``` and the checker one line per file and a summary: ``` OK rtg-0001.trf -> 28 players, 9 round(s) checked, standings OK OK rtg-0002.trf -> 49 players, 5 round(s) checked, standings OK ... summary: 20 OK ``` ## The checker: `fpc.py` ```bash python3 fpc.py rtg-out/rtg-0001.trf ``` The checker does two things with a file. 1. **Pairings.** Every round is paired again from what the file says about the rounds before it. If the computed pairings differ from those recorded in the file, each difference is listed: a pairing that was expected but is missing, a pairing that is in the file but was not expected, and boards whose colours are reversed. 2. **Standings.** From the results and from the tie-breaks the file lists (record `212` or `202`), the ranking is computed by C.07 and compared with the points (columns 81–84) and the ranks (columns 86–89) of every player. Again each difference is listed. A report looks like this: ``` OK rtg-0001.trf -> 28 players, 9 round(s) checked, standings OK tournament: RTG Tournament 1 checked with the engine of FairPair 1.0.4 (C.04.3 as valid from 1 Feb 2026) round 1: OK - 14 game(s), 0 pairing-allocated bye(s), 0 arbiter bye(s) round 2: OK - 12 game(s), 1 pairing-allocated bye(s), 3 arbiter bye(s) ... round 7: OK - 12 game(s), 0 pairing-allocated bye(s), 4 arbiter bye(s) - colours not verifiable: 1 forfeited game(s) (TRF records no colour for those) ... standings: OK - 28 players, ranked by PTS, BH/C1, BH, SB (record 212) ``` A mismatch is reported like this (an excerpt; two boards of round 3 of a generated file were swapped by hand): ``` MISMATCH changed.trf -> 12 players, 5 round(s) checked, standings MISMATCH round 3: MISMATCH - missing pairing 1-3 (expected, but not in the file) - missing pairing 4-9 (expected, but not in the file) - unexpected pairing 1-9 (in the file, but not expected) - unexpected pairing 3-4 (in the file, but not expected) standings: MISMATCH - ranked by PTS, BH/C1, BH, SB (record 212) - player #4: rank 6 in the file, expected 5 ``` Players are named by their starting rank number, as in the file. ### Exit code | Code | Meaning | |---|---| | `0` | Pairings and standings of every file match. | | `1` | At least one file has a mismatch. | | `2` | At least one file could not be read as a tournament file. | ### Options ```bash python3 fpc.py rtg-out/rtg-0001.trf --round 3 python3 fpc.py rtg-out/rtg-0001.trf --no-standings python3 fpc.py rtg-out/rtg-0001.trf --standings-only --table python3 fpc.py rtg-out/rtg-0001.trf --standings-only --tie-breaks BH/C1,BH,SB python3 fpc.py rtg-out/rtg-0001.trf --json python3 fpc.py rtg-out/rtg-0001.trf --lang de python3 fpc.py -check rtg-out/rtg-0001.trf python3 fpc.py --version ``` | Option | Meaning | |---|---| | `FILE [FILE ...]` | One or more tournament files. | | `-r N`, `--round N` | Check the pairings of this round only. The standings are then not checked: they belong to the state after the last round. | | `--no-standings` | Check the pairings only. | | `--standings-only` | Check the standings only; no round is paired again. | | `--tie-breaks LIST` | Rank by these tie-breaks instead of those the file lists, comma-separated, for example `BH/C1,BH,SB`. The points always come first. | | `--table` | Print the standings as computed, with every tie-break value, next to the rank recorded in the file. | | `--short` | One line per file. | | `--json` | Machine-readable report (see below). | | `--engine auto\|dutch\|javafo` | Which rules the pairings are checked by. `auto` (the default) follows the file — see “Which rules”. | | `--baku` | Assume Baku acceleration (C.04.7) even if the file does not state it. | | `--ga-limit N` | With acceleration: the starting rank number of the last player of group GA. `0` derives it from the number of players. | | `--lang en\|de` | Language of the report and of this help. English is the default. | | `-check`, `--check` | Accepted for compatibility with the invocation shown in the TEC Manual (3.9.4.2 c). Checking is what the tool does anyway. | | `--version` | Print the version of the program and the fingerprint of its pairing and tie-break modules (see “Version and integrity”). | | `-h`, `--help` | Print the help. | Every option also has a German name (`--runde`, `--wertungen`, `--tabelle`, `--kurz`, `--ohne-rangliste`, `--nur-rangliste`, `--baku-grenze`, `--sprache`). Both names work in both languages. ### File formats The checker reads TRF26 and the two earlier versions, TRF16 and TRF06, in UTF-8 or in the Windows code page. Whatever it notices about a file — a record it does not know, a result code without an opponent, forbidden pairings (record `260`), a deviating point allocation (record `299`) — is printed in the report as a `file note`. Features FairPair does not support are reported, not applied. ### Which rules With `--engine auto` the checker follows the file: * Record `192` states `FIDE_DUTCH_2026` (or its earlier name `FIDE_DUTCH_2025`, or `FIDE_DUTCH` for a tournament that started on or after 1 February 2026): FairPair's own engine, rules effective from 1 February 2026. Baku acceleration is taken from `FIDE_DUTCH_2026_BAKU` and from the records `250`. * Record `192` states `FIDE_DUTCH_2017`: JaVaFo 2.2, rules valid until 31 January 2026 (needs Java). * No record `192`: the rules in force on the first day of the tournament (record `042`); without a readable date, the earlier rules. * Record `192` states another system (`FIDE_DUBOV`, `CUSTOM_SWISS`, …): the rounds are not paired again. The report says so; the standings are still checked. ### What cannot be checked The report states these cases itself. * **Initial colour not recorded.** The colour of the top board in round 1 is drawn by lot. If the file records the draw (record `152`), the colours of round 1 are checked against it. If it does not, the draw is read off round 1 itself; checked is then that all boards of round 1 fit *one* draw. * **Forfeited games.** A tournament file records no colour for a forfeited game. The pairing of such a board is checked, its colours are not (`colours not verifiable`). * **Games without a result.** A file written while a round is in progress contains pairings without a result in its last round. The pairings are checked, and so are the standings — by the rule FairPair applies when it writes such a file: the points count everything already decided in the round in progress, the tie-breaks are those after the last finished round. The report names the round in progress. A game without a result in a round *before* the last one leaves the standings unchecked (`not checked`). The file format has no code for a game that is paired but not yet played, so not every program reads such a file: JaVaFo 2.2 reads and checks it, bbpPairings 6 rejects it (`Invalid line`). * **No ranks in the file.** If the rank column holds only the starting rank numbers and no tie-breaks are listed, there are no standings to check. * **Another point system.** The standings are checked for the scoring 1 / ½ / 0 only. ### The JSON report `--json` prints a list with one object per file. The field names and the status values are German identifiers; they are part of the format and do not change with `--lang`. | Field | Content | |---|---| | `datei` | The file. | | `status` | Verdict on the file: `ok`, `abweichung` (mismatch), `fehler` (a round could not be paired), `unlesbar` (not readable as a tournament file). | | `programm` | Name and version of the program the file was checked with, for example `FairPair 1.0.4`. | | `paarungen` | Verdict on the pairings alone. | | `paarungen_ungeprueft` | Empty, or the tournament type because of which the rounds were not paired again (a file that states a system other than the Dutch). | | `rangliste` | The standings: `status` (`ok`, `abweichung`, `ungeprueft` = not checked), `quelle` (the record the tie-breaks come from), `wertungen` (the tie-breaks listed), `angewandt` (the tie-breaks applied), `meldung` (why they were not checked), `laufende_runde` and `offene_partien` (0, or the round in progress and the number of its games without a result), `punkte_abweichungen` and `platz_abweichungen` (the players whose points or ranks differ). | | `turnier` | Name of the tournament. | | `engine` | `dutch` or `javafo`. | | `pab_wert` | Value of the pairing-allocated bye. | | `beschleunigung`, `baku_grenze` | `baku` or `keine` (none), and the last starting rank number of group GA. | | `spieler`, `runden_geprueft` | Number of players, number of rounds paired again. | | `warnungen_datei` | The file notes. | | `runden` | One object per round: `runde`, `status` (`ok`, `abweichung`, `leer` = no pairings, `fehler`), `partien` (games), `freilose` (pairing-allocated byes), `aussetzer` (byes on request), `abweichungen` (differing pairings), `farb_abweichungen` (reversed colours), `farben_ungeprueft` (boards whose colours could not be checked). | ## The generator: `rtg.py` ```bash python3 rtg.py --count 3 --players 40 --rounds 9 --seed 123 --folder rtg-big python3 fpc.py rtg-big/*.trf --short ``` Every tournament is played from the first to the last round: each round is paired by the engine, results are drawn at random, and the file is written in TRF26 with the standings by the chosen tie-breaks (record `212`, points and rank columns). Unless `--clean` is given, the tournaments contain what occurs in practice — byes on request (half point, full point, zero), pairing-allocated byes, forfeits, withdrawals and the unusual results a tournament program must handle. ### Options ```bash python3 rtg.py --count 3 --clean --folder rtg-clean python3 rtg.py --count 3 --baku --folder rtg-baku python3 rtg.py --count 3 --pab 0.5 --folder rtg-half python3 rtg.py --count 3 --tie-breaks DE,BH/C1,SB --folder rtg-tb python3 rtg.py --count 3 --tie-breaks random --ties lots --folder rtg-random python3 rtg.py --count 3 --results tec --folder rtg-tec python3 rtg.py --count 3 --rounds 9 --played 3 --baku --folder rtg-part python3 fpc.py rtg-clean/*.trf rtg-baku/*.trf rtg-half/*.trf rtg-tb/*.trf rtg-random/*.trf rtg-tec/*.trf rtg-part/*.trf --short python3 rtg.py --version ``` | Option | Meaning | |---|---| | `--count N` | How many tournaments to generate (default 1). | | `--players N` | Number of players; `0` (the default) draws a number between 8 and 60. | | `--rounds N` | Number of rounds; `0` (the default) draws a number between 5 and 9. | | `--played N` | Play only the first N rounds: a tournament in progress. The file still states the full number of rounds (record `142`), and everything that depends on it follows it — the plan of the acceleration, the rules for the last round. Read into the website, the next round can be paired. | | `--seed N` | Random seed. The same seed always yields the same files. | | `--folder DIR` | Output folder (default `rtg-out`). The files are named `rtg-0001.trf`, `rtg-0002.trf`, … | | `--clean` | Clean tournaments only: no byes, no forfeits, no unusual results. | | `--baku` | Generate with Baku acceleration (C.04.7). | | `--pab 1\|0.5` | Value of the pairing-allocated bye (default 1). | | `--tie-breaks LIST` | Tie-breaks for the standings, comma-separated (default `BH/C1,BH,SB`). `random` draws one to four of the mandatory tie-breaks for each tournament; `none` ranks by points only. | | `--ties shared\|lots` | Players still level after all tie-breaks: `shared` gives them the same rank (the default); `lots` separates them in the order of their starting rank numbers. | | `--results simple\|tec` | How results are drawn: `simple` (the default: 30 per cent draws, otherwise by rating expectancy) or `tec` (the statistical model the FIDE Technical Commission suggests for simulations). | | `--engine dutch\|javafo` | Pairing engine: `dutch` (the default, rules effective from 1 February 2026) or `javafo` (JaVaFo 2.2, rules valid until 31 January 2026; needs Java). | | `--lang en\|de` | Language of the output. | | `--version` | Print the version of the program and the fingerprint of its pairing and tie-break modules. | The German option names (`--anzahl`, `--spieler`, `--runden`, `--gespielt`, `--ordner`, `--sauber`, `--wertungen`, `--ergebnisse`, `--gleichstand`, `--sprache`) work as well. ### Tie-breaks The acronyms are those of the FIDE Handbook (C.07 and the annex “Mandatory Tie-Breaks”): `BH` Buchholz, `BH/C1` Buchholz Cut-1, `SB` Sonneborn-Berger, `DE` direct encounter, `WIN` number of wins, `PS` progressive scores, `ARO` average rating of opponents, `TPR` tournament performance rating, and so on, with the modifiers the annex defines (`/C1`, `/C2`, `/M1`, `/M2`, `/P`, …). All tie-breaks the annex lists as mandatory for individual tournaments are available. ## Checking other files The website writes its tournament file with “Download TRF” on the director's page; the checker reads that file like any other — and the files of other programs, in TRF26, TRF16 or TRF06. ## Version and integrity FairPair carries one version number, MAJOR.MINOR.PATCH (Semantic Versioning, as C.02.01, Article 5.9 asks for). The website, the tournament files it writes (record `182`), the checker and the generator all state the same number; in this package it is in the file `VERSION`. ```bash python3 fpc.py --version ``` prints the version and, in a second line, the **fingerprint** of the modules that pair and rank: one SHA-256 value over the eight Python files of the package. A version number belongs to exactly one fingerprint — the version history (`CHANGELOG.md`) lists it for every version. The same value is shown on the download page of the website the package comes from; if the two agree, the checker in your hands computes with the modules that website computes with. The fingerprint can be recomputed without the program: ``` sha256sum engine.py dutch.py paarung_gewichtet.py wertung.py fpc.py rtg.py cli_texte.py version.py | sha256sum ``` `SHA256SUMS` lists the checksum of every file of the package (`sha256sum -c SHA256SUMS`). The download page states the SHA-256 value of the archive itself. The same files always give the same archive, byte for byte. ## Licence The package may be used free of charge and passed on unchanged. The terms are in `LICENSE.txt`.