v2 introduces a functional API that replaces the class-based approach with simple, pure functions.
- All classes removed → replaced with functions
Playerclass →{ id, rating }objects- Multi-step setup → single function calls
- Team matches now use
scoreinstead ofrank(higher score = better performance) - Strong typing enforces at least 2 teams at compile time
Before (v1):
const match = new Duel({ kFactor: 15 });
match.addPlayer(new Player("player1", 1200), true);
match.addPlayer(new Player("player2", 1320), false);
const results = match.calculate();After (v2):
const results = calculateDuel(
{ id: "player1", rating: 1200 }, // winner
{ id: "player2", rating: 1320 }, // loser
{ kFactor: 15 }
);Before (v1):
const match = new FreeForAll();
match.addPlayer(new Player("player1", 1280), 1);
match.addPlayer(new Player("player2", 1300), 2);
match.addPlayer(new Player("player3", 1220), 3);
const results = match.calculate();After (v2):
const results = calculateFreeForAll([
{ player: { id: "player1", rating: 1280 }, score: 100 },
{ player: { id: "player2", rating: 1300 }, score: 75 },
{ player: { id: "player3", rating: 1220 }, score: 50 },
]);Before (v1):
const match = new TeamMatch({
calculationStrategy: CalculationStrategy.WEIGHTED_TEAMS,
});
const team1 = match.addTeam("team1", 2);
team1.addPlayer(new Player("p1", 1230));
team1.addPlayer(new Player("p2", 1260));
const team2 = match.addTeam("team2", 1);
team2.addPlayer(new Player("p3", 1120));
team2.addPlayer(new Player("p4", 1410));
const results = match.calculate();After (v2):
const winningTeam = {
players: [
{ id: "p1", rating: 1230 },
{ id: "p2", rating: 1260 },
],
score: 100, // higher score = better performance
};
const losingTeam = {
players: [
{ id: "p3", rating: 1120 },
{ id: "p4", rating: 1410 },
],
score: 75,
};
const results = calculateTeamMatch(winningTeam, losingTeam, {
strategy: CalculationStrategy.WEIGHTED_TEAMS
});For 3+ teams, use calculateMultiTeamMatch:
const teams = [team1, team2, team3];
const results = calculateMultiTeamMatch(teams, {
strategy: CalculationStrategy.WEIGHTED_TEAMS
});Before (v1):
const player1 = new Player("p1", 1460);
const expectedScore = player1.expectedScoreAgainst(1130);After (v2):
const expectedScore = calculateExpectedScore(1460, 1130);