4 #ifndef EVAL_ML_OPENMIDENDINGEVAL_H
5 #define EVAL_ML_OPENMIDENDINGEVAL_H
21 #define USE_TEST_PROGRESS
23 #define LEARN_TEST_PROGRESS
31 using namespace osl::progress::ml;
113 PROGRESS_INDEPENDENT_FEATURE_LIMIT
133 ProgressIndependentValueLimit = 4000
138 #ifdef USE_TEST_PROGRESS
147 non_pawn_attacked_ptype, piece_fork_turn;
152 rook_effect, bishop_effect, bishop_head, nosupport, ptype_yy, king3pieces;
154 MultiInt piece_stand_combination, piece_stand_y, knight_check,
155 knight_head, pawn_ptypeo, ptype_count_value, lance_effect_piece,
164 black_king_vertical, white_king_vertical;
170 CArray<std::pair<Square,int>, 2> knight_drop,
silver_drop, bishop_drop, rook_drop;
172 int progress_independent_value,
176 int black_attack_effect, black_attack_piece,
177 white_attack_effect, white_attack_piece,
179 int black_defense_effect, black_defense_piece,
186 static const int ROUND_UP = 2;
189 return v & (~(ROUND_UP-1));
193 const CArray<Square,2> kings = {{
194 state.kingSquare(
BLACK),
195 state.kingSquare(
WHITE),
197 gs_near_king_count.fill(0);
199 i < PtypeTraits<GOLD>::indexLimit; ++i)
201 const Piece p = state.pieceOf(i);
205 const int y_diff = std::abs(pos.
y() - kings[p.
owner()].y());
206 const int x_diff = std::abs(pos.
x() - kings[p.
owner()].x());
207 if (y_diff <= 2 && x_diff <= 3)
209 ++gs_near_king_count[p.
owner()][
std::max(x_diff, y_diff) - 1];
214 i < PtypeTraits<SILVER>::indexLimit; ++i)
216 const Piece p = state.pieceOf(i);
220 const int y_diff = std::abs(pos.
y() - kings[p.
owner()].y());
221 const int x_diff = std::abs(pos.
x() - kings[p.
owner()].x());
222 if (y_diff <= 2 && x_diff <= 3)
224 ++gs_near_king_count[p.
owner()][
std::max(x_diff, y_diff) - 1];
231 (
const NumEffectState &state=NumEffectState(),
242 return initialized_flag;
244 static bool setUp(
const char *filename);
246 static std::string defaultFilename();
249 return progress_independent_value + recalculated_value + piece_pair_value
250 + piece_pair_king_value[
BLACK] + piece_pair_king_value[
WHITE];
255 return king_table_value + piece_stand_value +
256 king25_effect_each[
BLACK] + king25_effect_each[
WHITE] +
257 ptypex + ptypey + rook_mobility + bishop_mobility + lance_mobility +
258 rook_effect + bishop_effect +
259 piece_stand_combination + piece_stand_turn[turn] +
260 rook_pawn + pawn_drop + piece_stand_y + knight_check +
261 pawn_advance + pawn_ptypeo + promoted_minor_piece +
263 non_pawn_attacked[turn] + non_pawn_attacked_ptype[turn] +
264 ptype_yy + king3pieces + bishop_head + knight_head
265 + rook_promote_defense +
266 ptype_count_value + lance_effect_piece + ptype_y_pawn_y +
267 bishop_and_king + piece_fork_turn[turn] + rook_silver_knight + bishop_silver_knight +
268 recalculated_stage_value;
272 return stageValue()[0];
276 return stageValue()[1];
280 return stageValue()[2];
290 if (value > ProgressIndependentValueLimit) {
291 int diff = value - ProgressIndependentValueLimit;
292 value = ProgressIndependentValueLimit
293 + diff * progress/progress_max;
295 else if (value < -ProgressIndependentValueLimit) {
296 int diff = value + ProgressIndependentValueLimit;
297 value = -ProgressIndependentValueLimit
298 + diff * progress/progress_max;
305 const int progress = this->progress.
progress();
306 int progress_independent = use_progress_independent_value_limit
307 ? progressIndependentValueAdjusted
308 (progressIndependentValue(), progress, progress_max)
309 : progressIndependentValue();
310 int sum = progress_independent * progress_max;
313 sum += openingValue() * 2*(c - progress);
314 sum += midgameValue() * 2*progress;
318 sum += midgameValue() * 2*(progress_max - progress);
319 sum += endgameValue() * 2*(progress - c);
324 int composeOpenMid2Endgame()
const
327 const int progress = this->progress.
progress();
328 const int c0 = progress_max/3, c1 = c0*2;
330 const int w2 = progress_max - c1;
333 int progress_independent = use_progress_independent_value_limit
334 ? progressIndependentValueAdjusted
335 (progressIndependentValue(), progress, progress_max)
336 : progressIndependentValue();
337 int sum = progress_independent * c0;
338 const MultiInt stage_sum = stageValue();
341 sum += stage_sum[0] * (c0 - progress);
342 sum += stage_sum[1] * progress;
344 else if (progress < c1)
346 sum += stage_sum[1] * (c1 - progress);
347 sum += stage_sum[2] * (progress-c0);
351 sum += stage_sum[2] * (progress_max - progress);
352 sum += stage_sum[3] * (progress - c1);
361 #ifdef USE_TEST_PROGRESS
363 cache = roundUp(composeOpenMid2Endgame());
365 cache = roundUp(composeOpenMidEndgame());
369 # error "not supported"
371 cache = roundUp(progressIndependentValue() * 16 +
372 openingValue() * (16 - progress.progress16().value()) +
373 endgameValue() * progress.progress16().value());
381 assert(turn == state.turn());
384 if (! rook_drop[turn].first.isPieceStand()) {
385 assert(state.hasPieceOnStand(turn,
ROOK));
386 suggest =
Move(rook_drop[turn].first,
ROOK, turn);
387 best_value = rook_drop[turn].second;
389 assert(best_value >= 0);
390 if (bishop_drop[turn].second > best_value) {
391 assert(! bishop_drop[turn].first.isPieceStand());
392 assert(state.hasPieceOnStand(turn,
BISHOP));
393 suggest =
Move(bishop_drop[turn].first,
BISHOP, turn);
394 best_value = bishop_drop[turn].second;
396 if (silver_drop[turn].second > best_value) {
397 assert(! silver_drop[turn].first.isPieceStand());
398 assert(state.hasPieceOnStand(turn,
SILVER));
399 suggest =
Move(silver_drop[turn].first,
SILVER, turn);
400 best_value = silver_drop[turn].second;
402 if (knight_drop[turn].second > best_value
403 && state.hasPieceOnStand(turn,
KNIGHT)) {
404 assert(! knight_drop[turn].first.isPieceStand());
405 suggest =
Move(knight_drop[turn].first,
KNIGHT, turn);
406 best_value = knight_drop[turn].second;
410 int expect(
const NumEffectState &state,
Move move)
const;
412 void updateSub(
const NumEffectState &new_state,
Move last_move);
413 void update(
const NumEffectState &new_state,
Move last_move);
416 return Progress32(progress.progress16(
BLACK).value()
417 + progress.progress16(
WHITE).value());
419 const Progress16
progress16()
const {
return progress.progress16(); }
425 #ifdef USE_TEST_PROGRESS
442 #ifdef USE_TEST_PROGRESS
455 static void setRandom();
456 static void resetWeights(
const int *w,
size_t length);
459 return use_progress_independent_value_limit;
462 template <
class Reader>
463 static void doResetWeights(Reader& reader);
466 using ml::OpenMidEndingEval;
468 using eval::OpenMidEndingEval;
471 #endif // EVAL_ML_OPENMIDENDINGEVAL_H