4 #ifndef EVAL_ML_OPENMIDENDINGEVAL_H
5 #define EVAL_ML_OPENMIDENDINGEVAL_H
18 #define USE_TEST_PROGRESS
20 #define LEARN_TEST_PROGRESS
110 PROGRESS_INDEPENDENT_FEATURE_LIMIT
130 ProgressIndependentValueLimit = 4000
145 rook_effect, bishop_effect, bishop_head, nosupport, ptype_yy, king3pieces;
179 static const int ROUND_UP = 2;
182 return v & (~(ROUND_UP-1));
190 gs_near_king_count.
fill(0);
192 i < PtypeTraits<GOLD>::indexLimit; ++i)
198 const int y_diff = std::abs(pos.
y() - kings[p.
owner()].y());
199 const int x_diff = std::abs(pos.
x() - kings[p.
owner()].x());
200 if (y_diff <= 2 && x_diff <= 3)
202 ++gs_near_king_count[p.
owner()][
std::max(x_diff, y_diff) - 1];
207 i < PtypeTraits<SILVER>::indexLimit; ++i)
213 const int y_diff = std::abs(pos.
y() - kings[p.
owner()].y());
214 const int x_diff = std::abs(pos.
x() - kings[p.
owner()].x());
215 if (y_diff <= 2 && x_diff <= 3)
217 ++gs_near_king_count[p.
owner()][
std::max(x_diff, y_diff) - 1];
235 return initialized_flag;
237 static bool setUp(
const char *filename);
239 static std::string defaultFilename();
242 return progress_independent_value + recalculated_value + piece_pair_value
243 + piece_pair_king_value[
BLACK] + piece_pair_king_value[
WHITE];
248 return king_table_value + piece_stand_value +
249 king25_effect_each[
BLACK] + king25_effect_each[
WHITE] +
250 ptypex + ptypey + rook_mobility + bishop_mobility + lance_mobility +
251 rook_effect + bishop_effect +
252 piece_stand_combination + piece_stand_turn[turn] +
253 rook_pawn + pawn_drop + piece_stand_y + knight_check +
254 pawn_advance + pawn_ptypeo + promoted_minor_piece +
256 non_pawn_attacked[turn] + non_pawn_attacked_ptype[turn] +
257 ptype_yy + king3pieces + bishop_head + knight_head
258 + rook_promote_defense +
259 ptype_count_value + lance_effect_piece + ptype_y_pawn_y +
260 bishop_and_king + piece_fork_turn[turn] + rook_silver_knight + bishop_silver_knight +
261 recalculated_stage_value;
265 return stageValue()[0];
269 return stageValue()[1];
273 return stageValue()[2];
283 if (value > ProgressIndependentValueLimit) {
284 int diff = value - ProgressIndependentValueLimit;
285 value = ProgressIndependentValueLimit
286 + diff * progress/progress_max;
288 else if (value < -ProgressIndependentValueLimit) {
289 int diff = value + ProgressIndependentValueLimit;
290 value = -ProgressIndependentValueLimit
291 + diff * progress/progress_max;
298 const int progress = this->progress.
progress();
299 int progress_independent = use_progress_independent_value_limit
300 ? progressIndependentValueAdjusted
301 (progressIndependentValue(), progress, progress_max)
302 : progressIndependentValue();
303 int sum = progress_independent * progress_max;
306 sum += openingValue() * 2*(c - progress);
307 sum += midgameValue() * 2*progress;
311 sum += midgameValue() * 2*(progress_max - progress);
312 sum += endgameValue() * 2*(progress - c);
317 int composeOpenMid2Endgame()
const
320 const int progress = this->progress.
progress();
321 const int c0 = progress_max/3, c1 = c0*2;
323 const int w2 = progress_max - c1;
326 int progress_independent = use_progress_independent_value_limit
327 ? progressIndependentValueAdjusted
328 (progressIndependentValue(), progress, progress_max)
329 : progressIndependentValue();
330 int sum = progress_independent * c0;
331 const MultiInt stage_sum = stageValue();
334 sum += stage_sum[0] * (c0 - progress);
335 sum += stage_sum[1] * progress;
337 else if (progress < c1)
339 sum += stage_sum[1] * (c1 - progress);
340 sum += stage_sum[2] * (progress-c0);
344 sum += stage_sum[2] * (progress_max - progress);
345 sum += stage_sum[3] * (progress - c1);
355 cache = roundUp(composeOpenMid2Endgame());
357 cache = roundUp(composeOpenMidEndgame());
364 assert(turn == state.
turn());
367 if (! rook_drop[turn].first.isPieceStand()) {
369 suggest =
Move(rook_drop[turn].first,
ROOK, turn);
370 best_value = rook_drop[turn].second;
372 assert(best_value >= 0);
373 if (bishop_drop[turn].second > best_value) {
374 assert(! bishop_drop[turn].first.isPieceStand());
376 suggest =
Move(bishop_drop[turn].first,
BISHOP, turn);
377 best_value = bishop_drop[turn].second;
379 if (silver_drop[turn].second > best_value) {
380 assert(! silver_drop[turn].first.isPieceStand());
382 suggest =
Move(silver_drop[turn].first,
SILVER, turn);
383 best_value = silver_drop[turn].second;
385 if (knight_drop[turn].second > best_value
387 assert(! knight_drop[turn].first.isPieceStand());
388 suggest =
Move(knight_drop[turn].first,
KNIGHT, turn);
389 best_value = knight_drop[turn].second;
400 + progress.progress16(
WHITE).value());
430 static void setRandom();
431 static void resetWeights(
const int *w,
size_t length);
434 return use_progress_independent_value_limit;
437 template <
class Reader>
438 static void doResetWeights(Reader& reader);
441 using ml::OpenMidEndingEval;
443 using eval::OpenMidEndingEval;
446 #endif // EVAL_ML_OPENMIDENDINGEVAL_H