A library that calculates the ranking of match (often a tournament) in table tennis.
It follows the official NTTB rules for tournaments.
npm i @nttb/tt-match-ranking
You can find the documentation here: https://nttb.github.io/tt-match-ranking/
TTMatch
shouldn't that be called a competiton or tournament?import {
TTMatch, // The type that contains all the match data
parseSetScore, // An easy to use function for adding sets
generateMatchRank // The function that generates the ranking
} from "@nttb/tt-match-ranking";
////////////////////////////////////////////////////////////////
// 0. You can create your own player-information (or just use a string).
interface MyPlayerType {
name: string;
club: string;
}
////////////////////////////////////////////////////////////////
// 1. Define the match and set rules
const matchRules = {
victoryPoints: 2, // Players get 2 points when they are the winner
defeatPoints: 1 // Players get 1 points when they play and lose...
// ... so that players that refuse to play are at a bigger disadvantage.
};
const setRules = {
bestOf: 5, // A set is won when a player has 3 out of 5 games.
gameRules: { // A game is won when a player...
scoreMinimum: 11, // - ... has at least 11 points
scoreDistance: 2, // - ... has at least 2 points advantage
}
};
////////////////////////////////////////////////////////////////
// 2. Create the match/tournament.
const match = new TTMatch<MyPlayerType>();
////////////////////////////////////////////////////////////////
// 3. Add the players that are participating.
const playerA = match.addPlayer({ name: "Player A", club: "my-club" });
const playerB = match.addPlayer({ name: "Player B", club: "my-club" });
const playerC = match.addPlayer({ name: "Player C", club: "my-club" });
const playerD = match.addPlayer({ name: "Player D", club: "my-club" });
const playerE = match.addPlayer({ name: "Player E", club: "my-club" });
const playerF = match.addPlayer({ name: "Player F", club: "my-club" });
////////////////////////////////////////////////////////////////
// 4. Add the played sets
// A vs B -- Player A loses in 3 games
match.addSet(playerA, playerB, parseSetScore("0-11,0-11,0-11"));
// A vs C -- Player A wins in 4 games
match.addSet(playerA, playerC, parseSetScore("0-11,11-0,11-0,11-0"));
// A vs D -- Player A loses in 5 games.
match.addSet(playerA, playerD, parseSetScore("0-11,11-0,0-11,11-0,0-11"));
// A vs E -- Player A wins because player E refuses to play
match.addSet(playerA, playerE, parseSetScore("wo:home"));
// A vs F -- Unknown result, as the set has no clear winner.
match.addSet(playerA, playerF, parseSetScore("0-11"));
////////////////////////////////////////////////////////////////
// 5. Calculate the ranking
const ranking = generateMatchRank(match, matchRules, setRules);
////////////////////////////////////////////////////////////////
// X. Display the ranking
ranking.ranked.forEach((rank, i) => {
const pos = i + 1;
console.log(`${pos}. ${rank.player.name}`)
})
Generated using TypeDoc