I need help with he next problem.
I want to calculate with JS the single tournament structure with an array the ids like this:
`const playerIDs = [6, 2, 1, 4, 7, 3, 8, 5];`
As long as it is a multiple of 4 there is no problem. It all starts when the number of players is odd or not multiples of 4, like 6, 7, 9, 10.... In these case I would like to add the leftover players as 'bye'. These players advance to the next round without playing.
With multiple of 4:
[
[ [8, 1], [2, 7], [3, 4], [5, 6] ], // first round
[ [null, null], [null, null] ], // semifinal
[ [null, null] ] // final
];
no multiple of 4:
[
[ [8, 1], [2, 7], [3, 4], [5, 6], [9, 'bye'], [10,'bye'] ], // first round
[ [null, null], [null, null] ], // semifinal
[ [null, null] ] // final
];
I have found solutions for multiples of 4, for 6 players or even 10, but I don't know how long I will have to continue like this, and I think that is not the right way to go.
The problem is that there are many variants regarding the number of players who can participate in a tournament, and I cannot find a common solution for all of them.
Maybe I should add some restriction for the number of participants?
It doesn't matter if someone thinks of another way to do it other than with arrays.
Thanks!
Another way of thinking to solve my logic problem.