slashinfty / tournament-organizer

JavaScript library for running tournaments
https://slashinfty.github.io/tournament-organizer/
MIT License
51 stars 18 forks source link

Can not set number of rounds manually for a Swiss tournament #19

Closed omikulcik closed 1 year ago

omikulcik commented 1 year ago

Hi,

when managing a swiss format tournament I would like to have an option to play specified count of rounds and only after this number of rounds is played advance to the next phase.

Currently that is not possible I think because of

    start(): void {
        const players = this.players.filter(p => p.active === true);
        if ((this.stageOne.format === 'double-elimination' && players.length < 4) || players.length < 2) {
            throw `Insufficient number of players (${players.length}) to start event`;
        }
        if (this.sorting !== 'none') {
            players.sort((a, b) => this.sorting === 'ascending' ? a.value - b.value : b.value - a.value);
        }
        this.status = 'stage-one';
        this.round++;
        this.#createMatches(players);
        if (this.stageOne.format === 'swiss' && this.stageOne.rounds === 0) {
            this.stageOne.rounds = Math.ceil(Math.log2(this.players.length));
        } else {
            this.stageOne.rounds = this.matches.reduce((max, curr) => Math.max(max, curr.round), 0);
        }
    }

Specifically this.stageOne.rounds = this.matches.reduce((max, curr) => Math.max(max, curr.round), 0);

Is there please some way around?

slashinfty commented 1 year ago

Good catch! Should be fixed in v3.3.1

if (this.stageOne.format === 'swiss' && this.stageOne.rounds === 0) {
    this.stageOne.rounds = Math.ceil(Math.log2(this.players.length));
} else if (this.stageOne.format !== 'swiss') {
    this.stageOne.rounds = this.matches.reduce((max, curr) => Math.max(max, curr.round), 0);
}