slashinfty / tournament-organizer

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

Possibility to the the result of the match #22

Closed ricardo17coelho closed 12 months ago

ricardo17coelho commented 12 months ago

HI 👋

As far i understand is not possible to enter the result (scoreboard) to the match. Should this be added to the fn enterResult() or is the idea to add this as meta ? This would be nice on the enterResult() to be part of the standings

slashinfty commented 12 months ago

I am unsure exactly what you are asking. Could you give me a little more detail or an example of what you want?

ricardo17coelho commented 12 months ago

Hi @slashinfty

No problem. My question is not clear 😅

I'm think a lit bit about the case:

Result: Player 2 wins the match 3-2

If the score is added to the match, then the results can be added to the standings to display it as well ( like goals difference, how many goals scored, how many conceded )

My question is also based on this, that i'm trying to build with this (amazing) package ( see the values on the table: GF, GA, GD): Screenshot 2023-10-26 at 00 13 16

slashinfty commented 12 months ago

The matches array in the Player object (see here) has objects for each match, including the number of wins and losses in the match (which, in the case of sports, can be points).

Is this what you're looking for?

ricardo17coelho commented 12 months ago

No. I'm mean the scoreboard of the match is missing:

Match ID: 01 Player 1 scores 3 goals Player 2 scored 1 goal Result: Player 1 wins 3-1

Match ID: 02 Player 1 scores 2 goals Player 2 scored 2 goal Result: Draw wins 2-2

slashinfty commented 12 months ago

You can determine the result from the match information.

If you have two players in a match (example):

[
  Player {
    id: 'LTasmXDtIquJ',
    name: 'Player 1',
    active: true,
    value: 1,
    matches: [ [Object] ],
    meta: {}
  },
  Player {
    id: 'iwgzRFssrMvC',
    name: 'Player 2',
    active: true,
    value: 2,
    matches: [ [Object] ],
    meta: {}
  }
]
Match {
  id: 'N1vjDXxmusjH',
  round: 1,
  match: 1,
  active: false,
  bye: false,
  player1: { id: 'LTasmXDtIquJ', win: 3, loss: 1, draw: 0 },
  player2: { id: 'iwgzRFssrMvC', win: 1, loss: 3, draw: 0 },
  path: { win: null, loss: null },
  meta: {}
}

You can do:

const winner = match.player1.win > match.player2.win ? 1 : match.player2.win > match.player1.win ? 2 : 0;

console.log(`${winner === 1 ? player1.name : winner === 2 ? player2.name : 'Draw'} wins ${winner === 1 ? match.player1.win : match.player2.win}-${winner === 1 ? match.player2.win : match.player1.win}`);

And get:

Player 1 wins 3-1

I'm sure there's a simpler way to do it, but just demonstrating the possibility.

ricardo17coelho commented 12 months ago

ahhh. Sorry i had an small mistake. Now i understand it 😅 I'm sorry