Open RomeroCarranzaEmiliano opened 4 years ago
start working on it
var winner = Hand.winners([hand1, hand2]);
should return winner if hand rank equal
var winner = Hand.winners([hand1, hand2]);
should return winner if hand rank equal
@besoeasy I don't understand the relevance of your comment
+1
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 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 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.
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
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
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?