pokersolver icon indicating copy to clipboard operation
pokersolver copied to clipboard

return the position of winner/s when Hand.winners(hands_list) ?

Open RomeroCarranzaEmiliano opened this issue 5 years ago • 9 comments

When applying the module for my poker server I found interesting that the method winners doesn't return the position of the winner in the array of hands passed. I think it would be really useful. Do I start working on that or is there some solution to this problem that I'm not seeing?

RomeroCarranzaEmiliano avatar Feb 03 '20 21:02 RomeroCarranzaEmiliano

start working on it

besoeasy avatar Feb 25 '20 06:02 besoeasy

var winner = Hand.winners([hand1, hand2]);

should return winner if hand rank equal

besoeasy avatar Feb 25 '20 06:02 besoeasy

var winner = Hand.winners([hand1, hand2]);

should return winner if hand rank equal

@besoeasy I don't understand the relevance of your comment

RomeroCarranzaEmiliano avatar Feb 26 '20 20:02 RomeroCarranzaEmiliano

+1

austinberke avatar Mar 23 '20 02:03 austinberke

Had the same issue, I solved in a really nasty way that works:

    calculateWinningPlayer(cardExaminations) {
      const hands = []
      for (let i = 0; i < cardExaminations.length; i += 1) {
        const c = cardExaminations[i]
        const h = Hand.solve(c.hand)
        h.playerId = c.idx // AssignIdentifier
        hands.push(h)
      }
      const handWinners = Hand.winners(hands)
      return handWinners[0].playerId
    }

invasionofsmallcubes avatar Apr 06 '20 18:04 invasionofsmallcubes

@invasionofsmallcubes I created a list with the hand description for every player in their respective position(0 if there is no player in that position) and then compared the winner descr with the list and therefore the position of the winner. At simple sight yours seems cleaner

RomeroCarranzaEmiliano avatar Apr 06 '20 19:04 RomeroCarranzaEmiliano

@RomeroCarranzaEmiliano I think it’s not that clean because I’m dinamically changing the structure of the input without doing a domain meaningful object or something. If I find time I will submit a PR to fix the problem.

invasionofsmallcubes avatar Apr 15 '20 06:04 invasionofsmallcubes

Hey guys, facing the same issue..would be so much easier if the index was returned in the obj. Looking forward to this issue being closed.

Thanks

Kevin-Raptor avatar May 16 '20 21:05 Kevin-Raptor

Simple solution: winner() returns the winning object out of an array of hand objects, unaltered. So you can just add the index yourself to the hand objects before feeding them into the winners command.

var hand1 = Hand.solve(['Ad', 'As', 'Jc', 'Th', '2d', '3c', 'Kd']);
var hand2 = Hand.solve(['Ad', 'As', 'Jc', 'Th', '2d', 'Qs', 'Qd']);
hand1.index = 0;
hand2.index = 1;
var winner = Hand.winners([hand1, hand2]); // hand2
console.log(winner[0].index) // 1

notalexross avatar Aug 10 '20 18:08 notalexross