Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to use for a not even number of teams? #26

Closed
MykolaGolubyev opened this issue Jul 21, 2020 · 21 comments
Closed

Is it possible to use for a not even number of teams? #26

MykolaGolubyev opened this issue Jul 21, 2020 · 21 comments
Labels
question Further information is requested

Comments

@MykolaGolubyev
Copy link

Hello,
thank you for putting together this library. I used it to understand the rules of double elimination.
I also quickly tried to use it to see if it can solve the case for a number of teams that is not N^2.
I am new to terminology and saw in the readme that BYE is used only for seeding, but not sure if that means I can't calculate games and their order using this library.

@Drarig29
Copy link
Owner

Drarig29 commented Jul 21, 2020

I'm not a pro in the matter either.

But yes, BYEs are created for the purpose of filling the blanks when the number of participants isn't 2^N (by the way, I said "power of two", so it's not N^2 😁).

It's only for seeding because it's just like a "null" team. It'll be propagated through the matches.

Let's say you're expecting 4 participants but one won't be here, and you know it before doing the seeding. (or you can't welcome 16 participants and therefore expect 12, which is not a power of 2)

You have:

  • Team 1 vs. Team 2
  • Team 3 vs. BYE

You already know Team 3 will be the winner of the second match (it won't be played at all).

So the next round will match the winner of the first match against Team 3.

So BYEs can either be used to handle numbers of participants which are not a power of two, or to fill a blank when a participant can't be present.

If it happens after the seeding is done and you can't affect the structure because some matches were already played, then you can use forfeits.

Hope it clarifies a bit. Do not hesitate to ask more 😉

@Drarig29
Copy link
Owner

Drarig29 commented Jul 21, 2020

@MykolaGolubyev

but not sure if that means I can't calculate games and their order using this library

To precise my answer, the library is created on the idea that it will always be a number of teams that is 2^N. You won't be able to use it otherwise.

But, you can use 2^N and fill in the blanks with BYEs, which I found is very common in this area. And quite a good workaround.

@MykolaGolubyev
Copy link
Author

MykolaGolubyev commented Jul 21, 2020

2^N :)
Thank you for a prompt response. Could you please elaborate on the

fill in the blanks with BYEs?

I tried

participants: [
    'Team 1',
    'Team 2',
    'Team 3',
    null,
    'Team 4',
    null,
    'Team 5',
    null,
],

but then I wanted to make a match as Team 3 has won against blank I got an error saying no team is defined yet.

@Drarig29
Copy link
Owner

Drarig29 commented Jul 21, 2020

Right.

It's bad behavior, it wasn't intended to do that...

I'll correct that tomorrow and add tests about that. A new version will be published on npm.

I mostly wrote tests about my use cases. So yours are welcome!

Edit: Actually, not wrong.

@MykolaGolubyev
Copy link
Author

Nice, thank you

@Drarig29
Copy link
Owner

Drarig29 commented Jul 22, 2020

Okay. I just started investigating and actually it's normal behavior! Sorry, it was late yesterday 😂

BYE propagation and "automatic match winning" are done during the process of creating the stage with manager.create() because it's determined right from the start and can't be changed afterwards. (If you want to be able to change later, you'd need to use forfeits but apparently it's not your case.)

So you shouldn't have to do that:

but then I wanted to make a match as Team 3 has won against blank I got an error saying no team is defined yet.

It has already been done. Team 3 is automatically in the next match.

Just read my test about BYE propagation:

it('should propagate BYEs through the brackets', async () => {
const withByes = {
name: 'Example with BYEs',
type: 'double_elimination',
participants: [
'Team 1', null,
null, null,
],
settings: { seedOrdering: ['natural'], grandFinal: 'simple' },
};
await manager.create(0, withByes);
assert.equal((await storage.select('match', 2)).opponent1.id, 0);
assert.equal((await storage.select('match', 2)).opponent2, null);
assert.equal((await storage.select('match', 3)).opponent1, null);
assert.equal((await storage.select('match', 3)).opponent2, null);
assert.equal((await storage.select('match', 4)).opponent1, null);
assert.equal((await storage.select('match', 4)).opponent2, null);
assert.equal((await storage.select('match', 5)).opponent1.id, 0);
assert.equal((await storage.select('match', 5)).opponent2, null);
});

I understand they can be hard to read because I use direct access to IDs...

But if you use my viewer (brackets-viewer.js), here is a visual representation of the result of the same test:

image

And here, Team 1's id is 0.

@MykolaGolubyev
Copy link
Author

Nice! thank you for looking into this. And thanks for the visual representation.

I tried to use it yesterday for one of the projects and realized that I have to re-implement the storage as I need in memory representation only and didn't realize json db is writing to a file. Can I still use it in browser only environment?

@Drarig29
Copy link
Owner

Can I still use it in a browser only environment?

Right now, as it is shipped, no you can't.

Because the default storage interface implementation (for json) uses node.js file storage API...

But you could easily write an implementation of the interface which uses either localStorage to persist data (sadly, node-json-db can't write to it) or directly the memory without any persisting...

A pull request is welcome if you want to add your implementation

@MykolaGolubyev
Copy link
Author

Got it. PR may be tough as I will need get approval (per project based approval). I will look into storage interface. I briefly looked at it before and it looked more than a simple CRUD. Will give it a go. Thanks again for your help and responsiveness.

@Drarig29
Copy link
Owner

Drarig29 commented Jul 22, 2020

I don't think it's far from a simple CRUD... maybe types make things feel harder.

I've already written an implementation for a SQL storage in a private project, in JavaScript. I can post the code to give you a starting point if you want, because it's quite tedious 😁

@MykolaGolubyev
Copy link
Author

I most likely will need to keep it in memory and once in awhile store as a simplified json blob.
When you build your algorithm, did you use some paper or reverse engineered videos and screenshots of various brackets? I seen like 5 different visual representations and it just confuses me even more :)

@Drarig29
Copy link
Owner

No, sorry. No paper nor videos.

But I got a lot of inspiration from the website Toornament (you must create a free account), see the Credits section in the readme.

If you want some help, you can contact me on Discord, if you have an account.

@Drarig29 Drarig29 added the question Further information is requested label Mar 9, 2021
@nakullondhe
Copy link

Wanted to add another use case, as in our system if both teams do not show up and the we'll need to disqualify both of them.
But also want to keep the tourney going. What's the solution in that case

@Drarig29
Copy link
Owner

@nakullondhe when people do not show up but the tournament is already started, you should use forfeits instead of BYEs.

@nakullondhe
Copy link

are forfeits possible for both the team together?

@Drarig29
Copy link
Owner

In an elimination tournament, a match must have a winner so forfeit for both teams isn't possible.

This is not very likely that two teams on the same match forfeit at the same time.

But you can set one as forfeit, let the other win, and forfeit it afterwards. But this is an edge case so I let the tournament organizer handle this.

@nakullondhe
Copy link

Okay, that method also works fine though.

Can you tell what are the accepted values at participantResult.

Screenshot 2022-01-29 230523

@Drarig29
Copy link
Owner

@nakullondhe
Copy link

exactly why i asked this question. You have put win , loss, draw but nothing about forfeit.

@Drarig29
Copy link
Owner

Drarig29 commented Jan 29, 2022

@nakullondhe
Copy link

thanks for your quick response, that's what I was looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants