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
245 stars 38 forks source link

match game count in a double-elimination bracket with BYE #184

Open bilmakovskiyruslan opened 11 months ago

bilmakovskiyruslan commented 11 months ago

In case I want to set up different best-of settings for each round. Steps:

  1. create bracket
  2. set matchSetupSettings
  3. update.seeding
    const manager = new BracketsManager(new InMemoryDatabase());
    const tournamentId = 0;
    const name = tournament.name;
    const type = 'double_elimination';
    const settings: StageSettings = { grandFinal: 'simple' };
    const seeding = ['1', '2', '3', null];
    await manager.create({ name, tournamentId, type, settings, seeding });

    const config = await manager.export();

    for await (const data of config.round) {
      await manager.update.matchChildCount('round', data.id, 1);
    }

    await manager.update.seeding(tournamentId, seeding);

    await manager.update.matchGame({
      id: 1,
      opponent1: { score: 1, id: null, result: 'loss' },
      opponent2: { score: 0, id: null, result: 'win' },
    });

    return await manager.export();

Expected result: the loser from the first round moved to the second round (lower bracket)

Actual Result: the loser from the first round sticks in the first round

Is it possible to move a user from the lower bracket to the next round automatically (if no opponent)?

image
Drarig29 commented 11 months ago

Hey! Really nice UI!

Indeed I would expect that the loser goes into loser bracket round 2. This is a bug.

I'll fix it soon. Do you confirm you can manually complete the match in loser bracket round 1?

Drarig29 commented 11 months ago

@bilmakovskiyruslan I can reproduce your issue, and I found a workaround that you can use for now.

    const manager = new BracketsManager(new InMemoryDatabase());
    const tournamentId = 0;
    const name = tournament.name;
    const type = 'double_elimination';
    const settings: StageSettings = { grandFinal: 'simple' };
    const seeding = ['1', '2', '3', null];
    await manager.create({ name, tournamentId, type, settings, seeding });

    const config = await manager.export();

    // Note: you don't need await here
-   for await (const data of config.round) {
+   for (const data of config.round) {

      // Note: do you know that you can use the `matchesChildCount` property in settings?
      // https://drarig29.github.io/brackets-docs/reference/model/interfaces/StageSettings.html#matchesChildCount
      await manager.update.matchChildCount('round', data.id, 1);
    }

    // You don't need this, and removing it should fix your issue.
-   await manager.update.seeding(tournamentId, seeding);

    await manager.update.matchGame({
      id: 1,
      opponent1: { score: 1, id: null, result: 'loss' },
      opponent2: { score: 0, id: null, result: 'win' },
    });

    return await manager.export();
bilmakovskiyruslan commented 11 months ago

yes, without await manager.update.seeding(tournamentId, seeding) bracket progress works fine