4#ifndef EVAL_ML_OPENMIDENDINGEVAL_H
5#define EVAL_ML_OPENMIDENDINGEVAL_H
18#define USE_TEST_PROGRESS
20#define LEARN_TEST_PROGRESS
130 ProgressIndependentValueLimit = 4000
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;
void fill(const T_simple &value=T_simple())
const Square square() const
bool hasPieceOnStand(Player player, Ptype ptype) const
const Piece pieceOf(int num) const
Square kingSquare() const
int y() const
将棋としてのY座標を返す.
int x() const
将棋としてのX座標を返す.
CArray< std::pair< Square, int >, 2 > bishop_drop
CArray< int, 5 > black_king_vertical
CArray< bool, 2 > can_check
int progressIndependentValue() const
int black_attack_supported_piece
MultiInt king_table_value
bool use_progress_independent_value_limit
static int roundUp(int v)
MultiIntPair king25_effect_each
static bool initialized()
CArray2d< int, 2, PTYPE_SIZE > ptype_board_count
CArray< int, 2 > non_pawn_stand_count
CArray< PieceMask, 2 > effect25
static int captureValue(PtypeO ptypeO)
int progress_independent_value
MultiInt stageValue() const
MultiIntPair king25_both_side
MultiInt rook_promote_defense
MultiIntPair non_pawn_attacked
CArray< int, 2 > piece_pair_king_value
int midgame2Value() const
MultiIntPair non_pawn_attacked_ptype
void updateGoldSilverNearKing(const NumEffectState &state)
int composeOpenMidEndgame() const
static OpenMidEndingPtypeTable Piece_Value
CArray2d< int, 2, 9 > pawns
static volatile LoadStatus initialized_flag
CArray< PieceMask, 2 > effected_mask
static Weights piece_pair_weights
CArray2d< int, 2, 3 > gs_near_king_count
CArray< PieceMask, 2 > effected_mask_for_attacked
bool progressIndependentValueLimit() const
CArray< PieceMask, 40 > attacked_mask
OpenMidEndingEval & operator=(const OpenMidEndingEval &src)
const Progress16 progress16() const
osl::progress::ml::NewProgress progress_t
CArray< int, 5 > black_vertical
CArray< PieceMask, 2 > effect25_supported
static int progressIndependentValueAdjusted(int value, int progress, int progress_max)
CArray< BoardMask, 2 > knight_fork_squares
int progressValue() const
const Progress32 progress32() const
const Move suggestMove(const NumEffectState &state) const
OpenMidEndingPtypeTable()
static int value(PtypeO ptypeO)
bool isValidPtypeO(int ptypeO)
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
CArray< int, PROGRESS_INDEPENDENT_FEATURE_LIMIT > progress_independent_values
CArray< MultiInt, STAGE_FEATURE_LIMIT > stage_values
ProgressIndependentFeature
@ PROGRESS_INDEPENDENT_FEATURE_LIMIT
@ BISHOP_EXCHANGE_SILVER_KING
@ NON_PAWN_ATTACKED_PTYPE_PAIR
@ NON_PAWN_ATTACKED_PTYPE
@ KING_PIECE_RELATIVE_NOSUPPORT
@ GOLD_AND_SILVER_NEAR_KING
@ PIECE_STAND_COMBINATION
@ KING25_EFFECT_SUPPORTED
@ KING25_EFFECT_COUNT_COMBINATION
@ MAJOR_CHECK_WITH_CAPTURE
static const char * name(ProgressIndependentFeature)