I’m sure something identical to this has been done, but I can’t find a direct answer.
A group of cards here is represented by a ulong with bits set. So, bit 0 is the 2 of clubs, bit 1 is the 3 of clubs, bit 13 is the 2 of diamonds…
A 2 card hand has 2 bits set, a 7 card hand has 7 bits set, obviously. So if you want to combine your hole cards with the board to see what you’ve got, you do
ulong myHoleCards = something;
ulong board = somethingElse;
ulong myHand = myHoleCards | board;
So DeaOutCards()is meant to deal out the board, or whatever, while taking into account that it shouldn’t deal cards that are already out. I believe it is dealing out certain hands too often, or too repetitively, which slightly fouls the results. I say “I believe” because it is tough to be certain where exactly the error is coming in. Am I making a mistake here, either in the logic or in my understanding of how random works?
using System.Diagnostics;
using System.Numerics;
namespace Enumerator;
public class Holdem
{
private Random random { get; } = new();
public ulong DealOutCards(int totalCards, ulong cardsAlreadyOut)
{
ulong returner = 0;
// Keep dealing cards until brought up to the total
// Cards already out will automatically be ignored by the or
while (BitOperations.PopCount(returner | cardsAlreadyOut) < totalCards)
{
returner |= (1ul << random.Next(51));
}
// Remove any cards already out
return returner & ~cardsAlreadyOut;
}
}