'Groups stage match generator
so im trying to create sort of "match generator" in TypeScript for All-In-All tournament type (i guess its called like that).
class Player {
id!: number
username!: string
points!: number
group!: string
}
class Match {
players: Player[] = []
scores: number[] = []
}
let players: Player[] = [];
for (let i = 1; i < 6; i++) {
let player = new Player();
player.id = i;
player.username = 'random' + i.toString();
player.points = 0;
players.push(player);
}
function test(n: number) {
for (let i = 0; i < n - 1; i++) {
console.log("Round" + i + 1);
for (let j = 0; j < n / 2; j++){
console.log(players[j].username + "VS" + players[players.length - 1 - j].username)
}
players.splice(1,0,players[4]);
players.pop();
}
}
console.log(test(players.length));
But for some reason im always getting matches pairs which i shouldn't.'
Test output :
[LOG]: "Round01"
[LOG]: "random1VSrandom5"
[LOG]: "random2VSrandom4"
[LOG]: "random3VSrandom3"
[LOG]: "Round11"
[LOG]: "random1VSrandom4"
[LOG]: "random5VSrandom3"
[LOG]: "random2VSrandom2"
[LOG]: "Round21"
[LOG]: "random1VSrandom3"
[LOG]: "random4VSrandom2"
[LOG]: "random5VSrandom5"
[LOG]: "Round31"
[LOG]: "random1VSrandom2"
[LOG]: "random3VSrandom5"
[LOG]: "random4VSrandom4"
[LOG]: undefined
I believe i just forgot or missed something , anyone could lead to a direction ?
Thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
