Card riddle source code
void DoCardSim()
{
const int TOTAL_TRIES = 1000000;
const int NUM_CARDS = 10;
double fPresetFlipTotal = 0;
double fPresetNoFlipTotal = 0;
double fRandomFlipTotal = 0;
double fRandomNoFlipTotal = 0;
double fFlip, fNoFlip;
int lowerBound = 1;
int upperBound = 100;
int aiCard[NUM_CARDS][2];
int iPresetFlipWinners = 0;
int iRandomFlipWinners = 0;
double fPresetFlipWinnerMeanStartingValue=0;
double fRandomFlipWinnerMeanStartingValue=0;
double fPresetNoFlipWinnerMeanStartingValue=0;
double fRandomNoFlipWinnerMeanStartingValue=0;
for (int i=0;i
{
iPresetFlipWinners++;
fPresetFlipWinnerMeanStartingValue += aiCard[card][cardSide];
}
else
fPresetNoFlipWinnerMeanStartingValue += aiCard[card][cardSide];
fFlip = aiCard[card][cardSide] * ((PL_Random(1,1000) < =500) ? 2 : 0.5f) - .10 * aiCard[card][cardSide];
fNoFlip = aiCard[card][cardSide];
fRandomFlipTotal += fFlip;
fRandomNoFlipTotal += fNoFlip;
if (fFlip > fNoFlip)
{
iRandomFlipWinners++;
fRandomFlipWinnerMeanStartingValue += aiCard[card][cardSide];
}
else
fRandomNoFlipWinnerMeanStartingValue += aiCard[card][cardSide];
}
char cTemp[500];
sprintf (cTemp,
"\nPreset:"
"\nFlip mean: %5.2f"
"\nNo-Flip mean: %5.2f"
"\nFlip advantage (penalty) %5.2f%%"
"\nFlip winners percent: %5.2f%%"
"\nFlip winners mean (starting): %5.2f"
"\nNo-Flip mean (starting): %5.2f"
"\n\n",
fPresetFlipTotal / TOTAL_TRIES,
fPresetNoFlipTotal / TOTAL_TRIES,
100 * ((fPresetFlipTotal / fPresetNoFlipTotal) - 1.0f),
100 * (iPresetFlipWinners / ((double)TOTAL_TRIES)),
fPresetFlipWinnerMeanStartingValue / iPresetFlipWinners,
fPresetNoFlipWinnerMeanStartingValue / (TOTAL_TRIES - iPresetFlipWinners)
);
PL_OutputDebug(cTemp);
sprintf (cTemp,
"\nRandom:"
"\nFlip mean: %5.2f"
"\nNo-Flip mean: %5.2f"
"\nFlip advantage (penalty) %5.2f%%"
"\nFlip winners percent: %5.2f%%"
"\nFlip winners mean (starting): %5.2f"
"\nNo-Flip mean (starting): %5.2f"
"\n\n",
fRandomFlipTotal / TOTAL_TRIES,
fRandomNoFlipTotal / TOTAL_TRIES,
100 * ((fRandomFlipTotal / fRandomNoFlipTotal) - 1.0f),
100 * (iRandomFlipWinners / ((double)TOTAL_TRIES)),
fRandomFlipWinnerMeanStartingValue / iRandomFlipWinners,
fRandomNoFlipWinnerMeanStartingValue / (TOTAL_TRIES - iRandomFlipWinners)
);
PL_OutputDebug(cTemp);
}