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
140 non_pawn_attacked_ptype, piece_fork_turn;
145 rook_effect, bishop_effect, bishop_head, nosupport, ptype_yy, king3pieces;
147 MultiInt piece_stand_combination, piece_stand_y, knight_check,
148 knight_head, pawn_ptypeo, ptype_count_value, lance_effect_piece,
157 black_king_vertical, white_king_vertical;
165 int progress_independent_value,
169 int black_attack_effect, black_attack_piece,
170 white_attack_effect, white_attack_piece,
172 int black_defense_effect, black_defense_piece,
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;
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);
446 #endif // EVAL_ML_OPENMIDENDINGEVAL_H
MultiInt rook_promote_defense
int max(Player p, int v1, int v2)
CArray< PieceMask, 2 > effect25
CArray< int, 2 > piece_pair_king_value
const Move suggestMove(const NumEffectState &state) const
CArray< MultiInt, STAGE_FEATURE_LIMIT > stage_values
static int progressIndependentValueAdjusted(int value, int progress, int progress_max)
static OpenMidEndingPtypeTable Piece_Value
static volatile LoadStatus initialized_flag
CArray< bool, 2 > can_check
ProgressN< 32 > Progress32
CArray2d< int, 2, 3 > gs_near_king_count
osl::progress::ml::NewProgress progress_t
int progressValue() const
int y() const
将棋としてのY座標を返す.
MultiInt stageValue() const
static int value(PtypeO ptypeO)
static bool initialized()
int x() const
将棋としてのX座標を返す.
bool isValidPtypeO(int ptypeO)
static Weights piece_pair_weights
CArray< int, 5 > white_vertical
static int roundUp(int v)
ProgressN< 16 > Progress16
const Piece pieceOf(int num) const
ProgressIndependentFeature
Square kingSquare() const
OpenMidEndingEval & operator=(const OpenMidEndingEval &src)
MultiIntPair kingx_blocked
int progressIndependentValue() const
MultiIntPair piece_stand_turn
MultiIntPair king_rook_bishop
bool hasPieceOnStand(Player player, Ptype ptype) const
bool progressIndependentValueLimit() const
CArray< PieceMask, 2 > effected_mask_for_attacked
CArray< BoardMask, 2 > knight_fork_squares
CArray2d< int, 2, PTYPE_SIZE > ptype_count
CArray< PieceMask, 40 > attacked_mask
CArray< PieceMask, 2 > effected_mask
const Progress16 progress16() const
int white_attack_supported_piece
const Square square() const
const Progress32 progress32() const
PtypeO
Player + Ptype [-15, 15] PtypeO の O は Owner の O.
void fill(const T_simple &value=T_simple())
void updateGoldSilverNearKing(const NumEffectState &state)
const Progress16 progress16() const
int midgame2Value() const
PtypeO captured(PtypeO ptypeO)
unpromoteすると共に,ownerを反転する.
bool use_progress_independent_value_limit
int composeOpenMidEndgame() const
CArray< PieceMask, 2 > effect25_supported
static int captureValue(PtypeO ptypeO)
MultiInt rook_silver_knight
CArray< int, 2 > non_pawn_stand_count
CArray< std::pair< Square, int >, 2 > silver_drop
CArray< int, PROGRESS_INDEPENDENT_FEATURE_LIMIT > progress_independent_values
MultiInt recalculated_stage_value
CArray2d< int, 2, 9 > pawns