pastly / cookerpoker

Poker game client/server in Rust WASM
0 stars 1 forks source link

Deck::deal_pocket() is not right #3

Closed pastly closed 2 years ago

pastly commented 3 years ago

Incoming branch that demonstrates the issues.

  1. Off by 1 because of the - 1. If there's one player, they should get card at index 51 and 50, but instead the function tries to give them card 51 and 51. Not possible.
  2. But the bigger problem is I think the algo is just wrong. Assume there's two players and we deal from the end of the deck (we do). The cards at the end are WXYZ. First call for the first player's cards gives him ZX (assuming fix from #1 is impl). The second call gives second player Y ... and not W. Whatever is before W. Because Y and W are now next to each other at it is wrong to skip.

I believe that we should .pop() .pop() to avoid this whole thing, even though it isn't how poker hands are dealt. It shouldn't matter mathematically.

Deedasmi commented 2 years ago

See 8a9daa006c3c94ec477cbd5b29d9d4297fd2db9d. Basically I changed deal_pocket() to deal all pockets for the game. This makes more sense anyway, since pockets are only dealt once, all at the same time. This allowed a little more control over the enumeration to fix the logic error.