goldfire / pokersolver

Javascript poker hand solver.
MIT License
373 stars 93 forks source link

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

Open RomeroCarranzaEmiliano opened 4 years ago

RomeroCarranzaEmiliano commented 4 years ago

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?

besoeasy commented 4 years ago

start working on it

besoeasy commented 4 years ago

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

should return winner if hand rank equal

RomeroCarranzaEmiliano commented 4 years ago

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

should return winner if hand rank equal

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

austinberke commented 4 years ago

+1

invasionofsmallcubes commented 4 years ago

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
    }
RomeroCarranzaEmiliano commented 4 years ago

@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

invasionofsmallcubes commented 4 years ago

@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.

Kevin-Raptor commented 4 years ago

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

notalexross commented 4 years ago

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