slashinfty / tournament-organizer

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

tournament.nextRound() does not work when all matches have draws. #9

Closed pedrohba1 closed 2 years ago

pedrohba1 commented 2 years ago

When running a tournament, if every match has a draw, the tourney.nextRound() simply stales the program and it does not end. Example program:

const TournamentOrganizer = require('./src/index')

// Create an event manager

const manager = new TournamentOrganizer.EventManager();

// Create a tournament
// First parameter can be set to a custom ID
// More options are available to set

const tourney = manager.createTournament(null, {
    name: 'My Example Tournament',
    format: 'swiss',
    playoffs: 'elim',
    cutLimit: 8,
    bestOf: 3,
    winValue: 3,
    drawValue: 1,
    tiebreakers: ['magic-tcg']
});

// Add players

tourney.addPlayer('Liam S');
tourney.addPlayer('Emma P.');
tourney.addPlayer('Noah B.');
tourney.addPlayer('Sophia R.');

// As many as desired

// Start the tournament

tourney.startEvent();

// Get all active matches

const active = tourney.activeMatches();

// Record a result

tourney.result(active[0], 0, 0,1);
tourney.result(active[1], 0, 0,1);

tourney.nextRound();
// Get standings

const standings = tourney.standings();

For our use case, it is important to have it work with this behaviour, where it will execute the next round even if all matches have a draw. I'm not quite sure where the problem is, but I would bet it is happening in line 692 or 693, when calling Algorithms.elim or lgorithms.doubleElim

slashinfty commented 2 years ago

The elimination and double elimination algorithms should have no effect on this. I'm guessing the Swiss pairing algorithm is not acting correctly.

I'm starting work on v2 where one of the big changes will be the Swiss pairing algorithm, so it doesn't fail like it seems to do time to time.

slashinfty commented 2 years ago

This should be resolved in v2.