1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
/*
This code has been submitted by Danil Suits <DSuits@silknet.com>, Mar 10, 1999.
It implements the cccc() and quality() functions. Both quality and cccc
use the algorithms described in _The Bridge World_, October 1982, with the
single exception that the values are multiplied by 100 (so that we can use
integers for them). Thus, a minimum opening bid is about 1200, rather
than 12.00 as expressed in the text.
In the original algorithm, everything was done with fractions. Floating
point rounding being what it is, I've decided to implement this instead as
integer math, until the last step.
As it happens, it is currently more convenient to use integers for the
return value from these functions as well So for the moment, Rescale is
basically a no-op.
*/
#include <assert.h>
#include "tree.h"
#include "dealer.h"
#include "c4.h"
#define C4_TYPE int
C4_TYPE Rescale (int nValue) {
return nValue;
}
C4_TYPE cccc (int seat) {
return Rescale (eval_cccc (seat));
}
C4_TYPE quality (int seat, int suit) {
return Rescale (suit_quality (seat, suit));
}
#undef C4_TYPE
int eval_cccc (int seat) {
int eval = 0;
int ShapePoints = 0;
/* For each suit.... */
int suit;
for (suit = SUIT_CLUB; suit <= SUIT_SPADE; ++suit) {
int Length = hs[seat].hs_length[suit];
int HasAce = HAS_CARD2 (suit, RK_ACE);
int HasKing = HAS_CARD2 (suit, RK_KING);
int HasQueen = HAS_CARD2 (suit, RK_QUEEN);
int HasJack = HAS_CARD2 (suit, RK_JACK);
int HasTen = HAS_CARD2 (suit, RK_TEN);
int HasNine = HAS_CARD2 (suit, RK_NINE);
int HigherHonors = 0;
if (Length < 3) {
ShapePoints += (3 - Length) * 100;
}
if (HasAce) {
eval += 300;
HigherHonors++;
}
if (HasKing) {
eval += 200;
if (Length == 1)
eval -= 150;
HigherHonors++;
}
if (HasQueen) {
eval += 100;
if (Length == 1)
eval -= 75;
if (Length == 2)
eval -= 25;
if (HigherHonors == 0)
eval -= 25;
HigherHonors++;
}
if (HasJack) {
if (HigherHonors == 2)
eval += 50;
if (HigherHonors == 1)
eval += 25;
HigherHonors++;
}
if (HasTen) {
if (HigherHonors == 2)
eval += 25;
if ((HigherHonors == 1) && HasNine)
eval += 25;
}
eval += suit_quality (seat, suit);
} /* end for (suit;...) */
if (ShapePoints == 0)
eval -= 50;
else
eval += ShapePoints - 100;
assert ((eval % 5) == 0);
return Rescale (eval);
}
int suit_quality (int seat, int suit) {
int Quality = 0;
int Length = hs[seat].hs_length[suit];
int HasAce = HAS_CARD2 (suit, RK_ACE);
int HasKing = HAS_CARD2 (suit, RK_KING);
int HasQueen = HAS_CARD2 (suit, RK_QUEEN);
int HasJack = HAS_CARD2 (suit, RK_JACK);
int HasTen = HAS_CARD2 (suit, RK_TEN);
int HasNine = HAS_CARD2 (suit, RK_NINE);
int HasEight = HAS_CARD2 (suit, RK_EIGHT);
int HigherHonors = 0;
int SuitFactor = Length * 10;
/*ACE*/
if (HasAce) {
Quality += 4 * SuitFactor;
HigherHonors++;
}
/*KING*/
if (HasKing) {
Quality += 3 * SuitFactor;
HigherHonors++;
}
/*QUEEN*/
if (HasQueen) {
Quality += 2 * SuitFactor;
HigherHonors++;
}
/*JACK*/
if (HasJack) {
Quality += 1 * SuitFactor;
HigherHonors++;
}
if (Length > 6) {
int ReplaceCount = 3;
if (HasQueen)
ReplaceCount -= 2;
if (HasJack)
ReplaceCount -= 1;
if (ReplaceCount > (Length - 6))
ReplaceCount = Length - 6;
Quality += ReplaceCount * SuitFactor;
}
else /* this.Length <= 6 */
{
if (HasTen) {
if ((HigherHonors > 1) || HasJack)
Quality += SuitFactor;
else
Quality += SuitFactor / 2;
}
if (HasNine) {
if ((HigherHonors == 2) || HasTen || HasEight)
Quality += SuitFactor / 2;
}
}
assert ((Quality % 5) == 0);
return Quality;
}
|