static int score_full_house_same_color (int field) { int i = find_n_of_a_kind (3, 0); if (i) { if (find_n_of_a_kind (2, i) + i == 7 || find_n_of_a_kind (5, 0)) return 20 + add_dice (); } return 0; }
static int score_full_house_kismet (int field) { int i = find_n_of_a_kind (3, 0); if (i) { if (find_n_of_a_kind (2, i) || find_n_of_a_kind (5, 0)) return 15 + add_dice (); } return 0; }
static int score_2_pair_same_color (int field) { int i = find_n_of_a_kind (2, 0); if (i) { if (find_n_of_a_kind (2, i) + i == 7 || find_n_of_a_kind (4, 0)) return add_dice (); } return 0; }
static void BuildTable(const player &p, int NumberOfRolls) { int i; int j; int k; int d; int d2 = -1; int overflow; for (i = 0; i < NUM_FIELDS; ++i) { if (p.score(i) >= 0) bc_table[i].value = -99; else bc_table[i].value = throwaway[i]; TagRerolls(&bc_table[i]); } /* ** HANDLING UPPER SLOTS */ /* ** first, we calculate the overflow of the upper ranks. that is, we ** count all the points we have left over from our 3-of-all rule ** if we get 3 of all in the upper ranks, we get a bonus, so if ** we get 4 of something, that means a lower roll may be acceptable, ** as long as we remain in the running for a bonus. overflow can ** be negative as well, in which case throwaway rolls are not ** encouraged, and a high roll will get a nice boost */ overflow = 0; for (i = 0; i < NUM_UPPER; ++i) { if (p.score(i) >= 0) continue; overflow += (count(i+1) - 3) * (i+1); } for (i = 0; i < NUM_UPPER; ++i) { if (p.score(i) >= 0) continue; ClearRerolls(&bc_table[i]); for (d = 0; d < 5; ++d) { if (DiceValues[d].val != i + 1) TagReroll(&bc_table[i],d); } /* ** ok. now we set a base value on the roll based on its count and ** how much it is worth to us. */ bc_table[i].value = count(i+1) * 8; /* ** we have to play games with the bonus. ** if we already have a bonus, then all free slots are candidates for ** throwing away - we only do this when there are no more rolls ** if this would get us a bonus, we make it very attractive ** ** if we get 3 of everything on the top, we get a bonus. so... ** if we have more than 3, we make the choice more attractive. ** if less than 3, we make it less attractive. ** if our overflow (any that are more than 3, summed up) covers up ** our lack (if we only have 2, and there were 4 6's), we ** do not penalize ourselves as much (since we're still in the ** running for a bonus) */ if (p.upperTotal() >= 63) { if (NumberOfRolls > 2) bc_table[i].value += 10; } else if (p.upperTotal() + count(i+1) * (i+1) >= 63) { bc_table[i].value += 35; } if (count(i+1) < 3) { if (overflow < (3 - count(i+1)) * (i+1)) bc_table[i].value -= (3 - count(i+1)) * 2; } else if (count(i+1) > 3) { bc_table[i].value += (count(i+1) - 3) * 2; } } /* ** HANDLING LOWER SLOTS */ /* ** first, we look for potential. these values will be larger than the ** single rolls but less than the made rolls (or those with higher value) ** ** we also do such thinking only if we're not supposed to be looking just ** for the best combinations... */ if (NumberOfRolls < 3) { /* ** searching for large straight... here we chicken out and only look at ** runs which might have possibilities */ if (p.score(H_LS) < 0) { for (i = 4; i > 0; --i) { d2 = find_straight(i, 0, 0 /* SDH 0 or 1? */); if (d2 == 0) continue; bc_table[H_LS].value = (40 * i) / 5; ClearRerolls(&bc_table[H_LS]); for (d = 1; d < 7; ++d) { if (count(d) > 0) { if (d < d2 || d >= d2 + i) k = count(d); else k = count(d) - 1; if (k < 1) continue; for (j = 0; j < 5; ++j) { if (DiceValues[j].val!=d) continue; TagReroll(&bc_table[H_LS],j); if (!--k) break; } } } break; } } /* ** searching for small straight... here we chicken out and only look at ** runs which might have possibilities */ if (p.score(H_SS) < 0) { for (i = 3; i > 0; --i) { d2 = find_straight(i, 0, 0 /* SDH 0 or 1? */); if (d2 == 0) continue; bc_table[H_SS].value = (30 * i) / 4; ClearRerolls(&bc_table[H_SS]); for (d = 1; d < 7; ++d) { if (count(d) > 0) { if (d < d2 || d >= d2 + i) k = count(d); else k = count(d) - 1; if (k < 1) continue; for (j = 0; j < 5; ++j) { if (DiceValues[j].val!=d) continue; TagReroll(&bc_table[H_SS],j); if (!--k) break; } } } break; } } /* ** searching for 3 of a kind */ if (p.score(H_3) < 0) { for (i = 2; i > 0; --i) { for (d = 6; d > 0; --d) { if (count(d) >= i) break; } if (d == 0) continue; ClearRerolls(&bc_table[H_3]); bc_table[H_3].value = (d * i); for (j = 0; j < 5; ++j) if (DiceValues[j].val != d) { TagReroll(&bc_table[H_3],j); } break; } } /* ** searching for 4 of a kind */ if (p.score(H_4) < 0) { for (i = 3; i > 0; --i) { for (d = 6; d > 0; --d) { if (count(d) >= i) break; } if (d == 0) continue; bc_table[H_4].value = (d * i); ClearRerolls(&bc_table[H_4]); for (j = 0; j < 5; ++j) if (DiceValues[j].val != d) { TagReroll(&bc_table[H_4],j); } break; } } /* ** searching for yahtzee... we can't set the potential value too high ** because if we fail, the value will be no better than 4 of a kind (or so) ** so, we make scoring the same as for 3-4 of a kind (this is 5 of a kind!) */ if (p.score(H_YA) < 0) { for (i = 4; i > 0; --i) { for (d = 6; d > 0; --d) { if (count(d) >= i) break; } if (d == 0) continue; bc_table[H_YA].value = (d * i); ClearRerolls(&bc_table[H_YA]); for (j = 0; j < 5; ++j) if (DiceValues[j].val != d) TagReroll(&bc_table[H_YA],j); break; } } /* ** searching for full house */ if (p.score(H_FH) < 0) { for (i = 4; i > 0; --i) { d = find_n_of_a_kind(i, 0); if (d == 0) continue; for (j = i; j > 0; --j) { d2 = find_n_of_a_kind(j, d); if (d2 > 0) break; } if (j == 0) continue; ClearRerolls(&bc_table[H_FH]); bc_table[H_FH].value = (i * 24 + j * 36) / 6; for (i = 0; i < 5; ++i) { if (DiceValues[i].val != d && DiceValues[i].val != d2) TagReroll(&bc_table[H_FH],i); } break; } } } /* ** now we look hard at what we got */ if (p.score(H_SS) < 0 && find_straight(4, 0, 0)) { d = find_straight(4, 0, 0); for (i = 0; i < 5; ++i) if (count(DiceValues[i].val) > 1 || DiceValues[i].val < d || DiceValues[i].val > d + 3) { TagReroll(&bc_table[H_SS],i); break; } bc_table[H_SS].value = 30; } if (p.score(H_LS) < 0 && find_straight(5, 0, 0)) { bc_table[H_LS].value = 40; ClearRerolls(&bc_table[H_LS]); } if (p.score(H_CH) < 0 && NumberOfRolls > 2) { bc_table[H_CH].value = add_dice(); if (bc_table[H_CH].value < 20) bc_table[H_CH].value /= 2; ClearRerolls(&bc_table[H_CH]); for (i = 0; i < 5; ++i) if (DiceValues[i].val < 4) TagReroll(&bc_table[H_CH],i); } if (p.score(H_FH) < 0) { d = find_n_of_a_kind(3, 0); if (d != 0) { if (find_n_of_a_kind(2, d)) { bc_table[H_FH].value = 25; ClearRerolls(&bc_table[H_FH]); } } } if (p.score(H_3) < 0) { d = find_n_of_a_kind(3, 0); if (d != 0) { bc_table[H_3].value = add_dice(); ClearRerolls(&bc_table[H_3]); for (i = 0; i < 5; ++i) if (d != DiceValues[i].val) TagReroll(&bc_table[H_3],i); } } if (p.score(H_4) < 0) { d = find_n_of_a_kind(4, 0); if (d != 0) { /* ** there will be a tie between 3 of a kind and 4 of a kind. we add 1 ** to break the tie in favor of 4 of a kind */ bc_table[H_4].value = add_dice() + 1; ClearRerolls(&bc_table[H_4]); for (i = 0; i < 5; ++i) if (d != DiceValues[i].val) TagReroll(&bc_table[H_4],i); } } if (find_n_of_a_kind(5, 0)) { if (p.score(H_YA) == 0) bc_table[H_YA].value = -99; /* scratch */ else bc_table[H_YA].value = 150; /* so he will use it! */ } }
static int score_kismet (int field) { if (find_n_of_a_kind (5, 0)) return 50 + add_dice (); return 0; }
static int score_4_of_a_kind_kismet (int field) { if (find_n_of_a_kind (4, 0)) return 25 + add_dice (); return 0; }
static int score_chance (int field) { return add_dice (); }
static int score_3_of_a_kind (int field) { if (find_n_of_a_kind (3, 0)) return add_dice (); return 0; }