Drarig29 / brackets-manager.js

A simple library to manage tournament brackets (round-robin, single elimination, double elimination).
https://drarig29.github.io/brackets-docs
MIT License
253 stars 40 forks source link

`manager.get.currentMatches` returns only Locked and Completed #172

Closed Tandashi closed 1 year ago

Tandashi commented 1 year ago

Currently I am running into the problem that manager.get.currentMatches only returns Locked and Completed matches. It doesn't return the matches of the next round as expected.

The round contains 3 Matches where Participants have BYE matches (so participant vs no-one) and 1 Participant vs Participant match. Do I need to update the BYE matches manually to mark as completed? (I would assume no if I understand to method Doc correctly)

Returns the matches that can currently be played in parallel.


If that is not the case here is my quick issue analysis. A Match that has a BYE it will always get the status Locked (we'll see later why). However the manager.get.currentMatches function checks if a rounds is completed as follows:

if (roundMatches.every(match => match.status >= Status.Completed))
    continue;

return roundMatches;

https://github.com/Drarig29/brackets-manager.js/blob/master/src/get.ts#L172

Since the Locked Status has a value of 0 this will never cause the round to be completed, thus returning a list of Locked and Completed Matches.

I would assume that the issue lies somewhere here:

if (hasBye(match)) // At least one BYE.
        return Status.Locked;

if (match.opponent1?.id === null && match.opponent2?.id === null) // Two TBD opponents.
    return Status.Locked;

if (match.opponent1?.id === null || match.opponent2?.id === null) // One TBD opponent.
    return Status.Waiting;

if (isMatchCompleted(match))
    return Status.Completed;

https://github.com/Drarig29/brackets-manager.js/blob/master/src/helpers.ts#L686C1-L687C30

The first if check will always cause a Match to get the Locked Status if it contains a BYE. Thus isMatchCompleted, which also accounts for BYE's, will never be reach. Simply returning the Completed Status instead of the Locked one in the first return could already solve the issue.

Drarig29 commented 1 year ago

Hey @Tandashi! Sorry for the delay.

I'm working on it, and thank you for reporting the issue 😄

Tandashi commented 1 year ago

All good. Thanks for the heads up :)

Drarig29 commented 1 year ago

@Tandashi could you try with the PR I opened?

To test it, you can do the following:

Tandashi commented 1 year ago

Will do in a bit :)

Drarig29 commented 1 year ago

Fix released in v1.5.9 😉