9 int calcNumPiecesNeeded(
const int cur_points,
const int points_on_row,
10 const int num_pieces_on_row,
const int threshold) {
11 if (points_on_row == num_pieces_on_row)
12 return threshold - cur_points;
13 const int points_needed = threshold - cur_points;
14 const int num_major = (points_on_row - num_pieces_on_row) / 4;
15 if (points_needed <= 5 * num_major)
16 return (points_needed + 4) / 5;
18 return num_major + (points_needed - 5 * num_major);
23 template <osl::Player Turn>
27 static const double normal_penalty = log(0.9);
28 static const double strong_penalty = log(0.8);
29 static const double weak_penalty = log(0.95);
30 static const double lower_bound = log(0.05);
34 const int my_king_y = myKingSquare.
y();
35 const int enemyCampMin = (Turn==
osl::BLACK) ? 1 : 7;
36 const int enemyCampMax = enemyCampMin + 2;
37 const int winning_threshold = (Turn==
osl::BLACK) ?
41 if (my_king_y < enemyCampMin || my_king_y > enemyCampMax) {
42 prob += ((Turn==
osl::BLACK)? (my_king_y - enemyCampMax) :
43 (enemyCampMin - my_king_y)) * weak_penalty;
48 int cur_piece_points = osl::enter_king::countPiecePointsInRange<Turn>(state, num_pieces, 1, 9, enemyCampMin, enemyCampMax);
51 if (num_pieces == 0) prob += 2 * strong_penalty;
52 else if (num_pieces < 3) prob += normal_penalty;
57 prob += (opp_effect_kingfront / 4) * strong_penalty;
61 if (opp_effect_kingfront == 0 && prob < normal_penalty)
62 prob -= normal_penalty;
63 if (num_pieces > 7 && prob < weak_penalty)
66 if (prob < lower_bound)
return 0.0;
70 if (cur_piece_points >= winning_threshold)
75 const int direction = (Turn==
osl::BLACK)? 1:-1;
76 const int base_y = (Turn==
osl::BLACK)? enemyCampMax : enemyCampMin;
77 double pos_penalty = weak_penalty;
78 for (
int yi = 1; yi <= 6; yi++) {
79 if (yi == 5) pos_penalty = normal_penalty;
80 int num_pieces_on_row = 0;
82 const int points_on_row = osl::enter_king::countPiecePointsOnRow<Turn>(state, num_pieces_on_row, base_y + direction * yi);
84 if (cur_piece_points + points_on_row >= winning_threshold) {
85 prob += calcNumPiecesNeeded(cur_piece_points, points_on_row, num_pieces_on_row, winning_threshold) * pos_penalty;
89 cur_piece_points += points_on_row;
90 prob += num_pieces_on_row * pos_penalty;
91 if (prob < lower_bound)
return 0.0;
99 return getProbability<osl::BLACK>(state);
101 return getProbability<osl::WHITE>(state);
106 template <osl::Player Turn>
110 static const double normal_penalty = log(0.9);
111 static const double strong_penalty = log(0.8);
112 static const double weak_penalty = log(0.95);
113 static const double lower_bound = log(0.05);
117 const int my_king_y = myKingSquare.
y();
118 const int enemyCampMin = (Turn==
osl::BLACK) ? 1 : 7;
119 const int enemyCampMax = enemyCampMin + 2;
120 const int winning_threshold = (Turn==
osl::BLACK) ?
124 if (my_king_y < enemyCampMin || my_king_y > enemyCampMax) {
125 const int dist = (Turn==
osl::BLACK)? (my_king_y - enemyCampMax) : (enemyCampMin - my_king_y);
126 prob += dist * normal_penalty;
131 int cur_piece_points = osl::enter_king::countPiecePointsInRange<Turn>(state, num_pieces, 1, 9, enemyCampMin, enemyCampMax);
135 if (num_pieces == 0) prob += 2 * strong_penalty;
136 else if (num_pieces < 10)
137 prob += ((12 - num_pieces) / 3) * normal_penalty;
142 prob += (opp_effect_kingfront / 4) * strong_penalty;
146 if (opp_effect_kingfront == 0 && prob < normal_penalty)
147 prob -= normal_penalty;
149 if (prob < lower_bound)
return 0.0;
153 if (cur_piece_points >= winning_threshold)
158 const int direction = (Turn==
osl::BLACK)? 1:-1;
159 const int base_y = (Turn==
osl::BLACK)? enemyCampMax : enemyCampMin;
160 double pos_penalty = weak_penalty;
161 for (
int yi = 1; yi <= 6; yi++) {
162 if (yi == 5) pos_penalty = normal_penalty;
163 int num_pieces_on_row = 0;
165 const int points_on_row = osl::enter_king::countPiecePointsOnRow<Turn>(state, num_pieces_on_row, base_y + direction * yi);
167 if (cur_piece_points + points_on_row >= winning_threshold) {
168 prob += calcNumPiecesNeeded(cur_piece_points, points_on_row, num_pieces_on_row, winning_threshold) * pos_penalty;
172 cur_piece_points += points_on_row;
173 prob += num_pieces_on_row * pos_penalty;
174 if (prob < lower_bound)
return 0.0;
178 if (winning_threshold - cur_piece_points <= 5)
179 prob += (winning_threshold - cur_piece_points) * strong_penalty;
181 if (prob < lower_bound)
return 0.0;
186 return getProbability27<osl::BLACK>(state);
188 return getProbability27<osl::WHITE>(state);
192 template <osl::Player Turn>
194 if (getProbability<Turn>(state) > threshold)
200 if (getProbability(state, Turn) > threshold)
205 template <osl::Player Turn>
207 if (getProbability27<Turn>(state) > threshold)
213 if (getProbability27(state, Turn) > threshold)
219 namespace enter_king {
221 double SimplePredictor::getProbability<osl::BLACK>
224 double SimplePredictor::getProbability<osl::WHITE>
228 double SimplePredictor::getProbability27<osl::BLACK>
231 double SimplePredictor::getProbability27<osl::WHITE>
235 bool SimplePredictor::predict<osl::BLACK>
238 bool SimplePredictor::predict<osl::WHITE>
242 bool SimplePredictor::predict27<osl::BLACK>
245 bool SimplePredictor::predict27<osl::WHITE>