public static bool HandWinOdds(ulong[] ourcards, ulong[] oppcards, ulong board, out double[] player, out double[] opponent)
{
uint ourbest, oppbest;
int count = 0;
int boardcount = BitCount(board);
int cards = boardcount + 2;
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 };
#if DEBUG
// Preconditions
foreach (ulong pocketcards in ourcards)
{
if (BitCount(pocketcards) != 2) throw new ArgumentOutOfRangeException("pocketcards");
}
foreach (ulong pocketcards in oppcards)
{
if (BitCount(pocketcards) != 2) throw new ArgumentOutOfRangeException("pocketcards");
}
if (boardcount > 5) throw new ArgumentOutOfRangeException("boardcards");
#endif
player = podds;
opponent = oodds;
if (boardcount == 0)
{
// Calculate monte carlo results
foreach (ulong pocketcards in ourcards)
{
if ((pocketcards & board) != 0UL) continue;
foreach (ulong opphand in oppcards)
{
if (((opphand & pocketcards) != 0UL) || (opphand & board) != 0UL) continue;
foreach (ulong handmask in Hand.RandomHands(board, pocketcards | opphand, 5, (5.0 / (ourcards.Length * oppcards.Length))))
{
ourbest = Evaluate(pocketcards | handmask, 7);
oppbest = Evaluate(opphand | handmask, 7);
if (ourbest > oppbest)
{
player[(uint)HandType(ourbest)] += 1.0;
count++;
}
else if (ourbest == oppbest)
{
player[(uint)HandType(ourbest)] += 0.5;
opponent[(uint)HandType(oppbest)] += 0.5;
count++;
}
else
{
opponent[(uint)HandType(oppbest)] += 1.0;
count++;
}
}
}
}
for (int i = 0; i < 9; i++)
{
player[i] = player[i] / count;
opponent[i] = opponent[i] / count;
}
return true;
}
else
{
// Calculate results
foreach (ulong pocketcards in ourcards)
{
if ((pocketcards & board) != 0UL) continue;
foreach (ulong opphand in oppcards)
{
if (((opphand & pocketcards) != 0UL) || (opphand & board) != 0UL) continue;
foreach (ulong handmask in Hands(board, pocketcards | opphand, 5))
{
ourbest = Evaluate(pocketcards | handmask, 7);
oppbest = Evaluate(opphand | handmask, 7);
if (ourbest > oppbest)
{
player[(uint)HandType(ourbest)] += 1.0;
count++;
}
else if (ourbest == oppbest)
{
player[(uint)HandType(ourbest)] += 0.5;
opponent[(uint)HandType(oppbest)] += 0.5;
count++;
}
else
{
opponent[(uint)HandType(oppbest)] += 1.0;
count++;
}
}
}
}
for (int i = 0; i < 9; i++)
{
player[i] = player[i] / count;
opponent[i] = opponent[i] / count;
}
return false;
}
}