You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
import { Tournament } from "../tournament/tournament"; |
|
|
|
export class RankingReport { |
|
constructor(public tournament: Tournament) {} |
|
|
|
printPlayerSummary() { |
|
const sortedPlayers = this.tournament.players.sort( |
|
(a, b) => a.playerId - b.playerId |
|
); |
|
for (const player of sortedPlayers) { |
|
const wins = player.games.reduce( |
|
(wins, game) => wins + Number(game.winner === player), |
|
0 |
|
); |
|
const losses = player.games.length - wins; |
|
const ratio = (wins / player.games.length).toFixed(3); |
|
const ladders = player.games.reduce( |
|
(ladders, game) => ladders + game.ladderCountForPlayer(player), |
|
0 |
|
); |
|
const snakes = player.games.reduce( |
|
(snakes, game) => snakes + game.snakeCountForPlayer(player), |
|
0 |
|
); |
|
|
|
console.log( |
|
`Player: ${player.playerId}: ` + |
|
[ |
|
`Win:${wins}`, |
|
`Lose:${losses}`, |
|
`Percent:${ratio}`, |
|
`Rolls:${player.rolls}`, |
|
`Ladders:${ladders}`, |
|
`Snakes:${snakes}`, |
|
].join(", ") + |
|
" ..." |
|
); |
|
} |
|
} |
|
}
|
|
|