-
Notifications
You must be signed in to change notification settings - Fork 0
/
c4.cpp
190 lines (146 loc) · 4.41 KB
/
c4.cpp
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
190
/*
This code has been submitted by Danil Suits <[email protected]>, 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"
static int has_card2(int s, int r, int seat) {
return HAS_CARD(curdeal, seat, (Card)make_card(s, r));
}
static int Rescale(int nValue) {
return nValue;
}
static int suit_quality(int seat, int suit) {
int Quality = 0;
int Length = hs[seat].hs_length[suit];
int HasAce = has_card2(suit, RK_ACE, seat);
int HasKing = has_card2(suit, RK_KING, seat);
int HasQueen = has_card2(suit, RK_QUEEN, seat);
int HasJack = has_card2(suit, RK_JACK, seat);
int HasTen = has_card2(suit, RK_TEN, seat);
int HasNine = has_card2(suit, RK_NINE, seat);
int HasEight = has_card2(suit, RK_EIGHT, seat);
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;
}
static 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, seat);
int HasKing = has_card2(suit, RK_KING, seat);
int HasQueen = has_card2(suit, RK_QUEEN, seat);
int HasJack = has_card2(suit, RK_JACK, seat);
int HasTen = has_card2(suit, RK_TEN, seat);
int HasNine = has_card2(suit, RK_NINE, seat);
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 cccc(int seat) {
return Rescale(eval_cccc(seat));
}
int quality(int seat, int suit) {
return Rescale(suit_quality(seat, suit));
}