void RollSelectedDice (void) { int i, cnt = 0; if (NumberOfRolls >= NUM_ROLLS) { return; } for (i = 0; i < NUMBER_OF_DICE; i++) { if (DiceValues[i].sel) { DiceValues[i].val = RollDie (); DiceValues[i].sel = 0; cnt++; lastRoll.DiceValues[i] = DiceValues[i].val; } } /* If no dice is selcted roll them all */ if (cnt == 0) { for (i = 0; i < NUMBER_OF_DICE; i++) { DiceValues[i].val = RollDie (); lastRoll.DiceValues[i] = DiceValues[i].val; } } UpdateAllDicePixmaps (); DeselectAllDice (); NumberOfRolls++; if (NumberOfRolls >= NUM_ROLLS) { say (_("Choose a score slot.")); } lastRoll.roll = NumberOfRolls; lastRoll.player = CurrentPlayer; }
void ComputerRolling (int player) { int i; int best; int bestv; int num_options = 1; int die_comp[NUMBER_OF_DICE]; double best_score; int ii, jj, kk; for (i = 0; i < NUMBER_OF_DICE; i++) { die_comp[i] = num_options; num_options *= 2; } double avg_score[num_options]; DiceInfo sav_DiceValues[NUMBER_OF_DICE]; memset (avg_score, 0, sizeof (avg_score)); memcpy (sav_DiceValues, DiceValues, sizeof (sav_DiceValues)); for (ii = 0; ii < num_options; ii++) { for (jj = 0; jj < NUM_TRIALS; jj++) { DiceInfo loc_info[NUMBER_OF_DICE]; memcpy (loc_info, sav_DiceValues, sizeof (loc_info)); for (kk = 0; kk < NUMBER_OF_DICE; kk++) { if (die_comp[kk] & ii) { loc_info[kk].val = RollDie (); } } memcpy (DiceValues, loc_info, sizeof (sav_DiceValues)); BuildTable (player); bestv = -99; for (i = NUM_FIELDS - 1; i >= 0; i--) { if (bc_table[i] >= bestv) { bestv = bc_table[i]; } } avg_score[ii] += bestv; } avg_score[ii] /= NUM_TRIALS; if (DisplayComputerThoughts) printf ("Set avg score for %d to %f\n", ii, avg_score[ii]); } best = 0; best_score = -99; for (ii = 0; ii < num_options; ii++) { if (avg_score[ii] >= best_score) { best = ii; best_score = avg_score[ii]; } } if (DisplayComputerThoughts) printf ("Best choice is %d val %f for dice ", best, best_score); /* Restore DiceValues */ memcpy (DiceValues, sav_DiceValues, sizeof (sav_DiceValues)); for (ii = 0; ii < NUMBER_OF_DICE; ii++) { if (die_comp[ii] & best) { DiceValues[ii].sel = 1; if (DisplayComputerThoughts) printf ("Reset to roll die %d value %d bit %d comp %d test %d\n", ii, DiceValues[ii].val, ii, best, ii & best); } else { DiceValues[ii].sel = 0; if (DisplayComputerThoughts) printf ("Reset NOT to roll die %d value %d bit %d comp %d test %d\n", ii, DiceValues[ii].val, ii, best, ii & best); } } }