public static void DetailedOddsWithMultiplePlayers(string pocket, string board, ulong dead, int playerCount, out double[] playerodds, out double[] oppodds, double duration)
{
#if DEBUG
if (!Hand.ValidateHand(board)) throw new ArgumentException();
if (playerCount < 1 || playerCount > 9) throw new ArgumentException();
if (Hand.BitCount(Hand.ParseHand(board)) > 5) throw new ArgumentException();
if (duration < 0.0) throw new ArgumentException();
#endif
Random rand = new Random();
ulong boardmask = Hand.ParseHand(board);
ulong[] pocketlist = PocketHands.Query(pocket, boardmask | dead);
double[] podds = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
double[] oodds = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
ulong[] opponent = new ulong[playerCount];
uint[] oppHandVal = new uint[playerCount];
double start = Hand.CurrentTime;
int count = 0;
ulong deadmask, finalboard, pocketmask;
uint best;
while ((Hand.CurrentTime - start) < duration)
{
pocketmask = Hand.RandomHand(rand, pocketlist, boardmask, 2);
// The order cards are dealt doesn't effect the resulting
// odds in a simulation like this. So for coding convienence
// we will draw the board cards before the opponents cards.
finalboard = Hand.RandomHand(rand, boardmask, pocketmask | dead, 5);
deadmask = pocketmask | dead | finalboard;
for (int i = 0; i < playerCount; i++)
{
deadmask |= opponent[i] = Hand.RandomHand(rand, 0UL, deadmask, 2);
oppHandVal[i] = Hand.Evaluate(opponent[i] | finalboard, 7);
}
uint handval = Hand.Evaluate(pocketmask | finalboard, 7);
Array.Sort<uint>(oppHandVal);
best = oppHandVal[playerCount - 1];
if (handval > best)
{
podds[Hand.HandType(handval)] += 1.0;
}
else if (handval == best)
{
podds[Hand.HandType(handval)] += 0.5;
oodds[Hand.HandType(best)] += 0.5;
}
else
{
oodds[Hand.HandType(best)] += 1.0;
}
count++;
}
if (count > 0)
{
for (int i = 0; i < podds.Length; i++)
{
podds[i] /= count;
oodds[i] /= count;
}
}
// The returned results
playerodds = podds;
oppodds = oodds;
}