catdadcode / poker-engine

32 stars 13 forks source link

Problem with distributing pot to winners #2

Open sangyoo91 opened 3 years ago

sangyoo91 commented 3 years ago

I found an error where when everyone folds, the pot goes to the highest hand even if the player has folded.

The pot should go to the one person who didnt fold .

table.winners shows the proper winner, but the chips go to the person with the actual highest hand

sangyoo91 commented 3 years ago

Upon looking further into this, I think table.showdown pots.eligiblePlayers doesn't consider player fold state.

catdadcode commented 3 years ago

I think this is fixed. Please test it out and if it still happens then bring me back some steps to reproduce and I'll tackle it :)

sangyoo91 commented 3 years ago

I made my own fixes locally for this, but I'll test it out.

catdadcode commented 3 years ago

Mind sharing those fixes? :sweat_smile:

sangyoo91 commented 2 years ago

I've strayed away from the project, but if I remember properly it was

 // Distribute pots and mark winners.
this.pots.forEach(pot => {
  pot.winners = findWinners(pot.eligiblePlayers); 
  const award = pot.amount / pot.winners!.length;
  pot.winners!.forEach(player => player.stackSize += award);
});

This part that was the problem.

I don't use type script but I believe I did

pot.winners = findWinners( pot.eligiblePlayers.filter((p)=> {
  return !p.folded
}) );

On a local js build I did. Hope this helps :D