From e67dfc5645e6c6abe23fba88733cf0bdbe20106f Mon Sep 17 00:00:00 2001 From: Calcitem Date: Mon, 14 Jun 2021 11:42:37 +0800 Subject: [PATCH] evaluate: Do not attack too early when first 5 moves If first 4 moves is placing at star point, move 5 temporarily use depth 1 search in order to make sure white player do not attack and try to block black. (For 9ms, star point is b4/d6/f4/d2) This changed the white's moves. For nine men's morris: If first 4 moves is: 1. b4 d6 2. f4 d2 Next move, white will place at a4/c4/e4/g4, now changed to place at d7/d5/d3/d1 If first 4 moves is: 1. b4 f4 2. d6 d2 Next move, white will place at b6, it is not wrong, now changed to place at d4/g4/d3/d1, it is not wrong too. Test result: Play against Perfect Database: 400 games. There is no significant change in the Draw rate. Play 90 games against the pre-improved version: White (New) Vs Black (Old) White's win rate increased to 20%, equivalent to Black's winning rate Originally less than 10%. --- include/config.h | 2 +- src/evaluate.cpp | 14 +++++++++++--- src/mills.cpp | 25 +++++++++++++++++++++++++ src/search.cpp | 2 ++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/include/config.h b/include/config.h index 6d6a09cb..a5d6a56e 100644 --- a/include/config.h +++ b/include/config.h @@ -25,7 +25,7 @@ #pragma execution_character_set("utf-8") #endif -//#define EVALUATE_MOBILITY +#define EVALUATE_MOBILITY //#undef QT_GUI_LIB diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 2a88c308..97532850 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -56,6 +56,13 @@ Value Evaluation::value() break; case Phase::placing: +#ifdef EVALUATE_MOBILITY + if (pos.piece_on_board_count(WHITE) + pos.piece_on_board_count(BLACK) <= 5) { + value += (Value)pos.get_mobility_diff(); + } + //break; +#endif /* EVALUATE_MOBILITY */ + pieceInHandDiffCount = pos.piece_in_hand_count(WHITE) - pos.piece_in_hand_count(BLACK); value += VALUE_EACH_PIECE_INHAND * pieceInHandDiffCount; @@ -77,12 +84,13 @@ Value Evaluation::value() break; case Phase::moving: - value = (pos.piece_on_board_count(WHITE) - pos.piece_on_board_count(BLACK)) * VALUE_EACH_PIECE_ONBOARD; - #ifdef EVALUATE_MOBILITY - value += pos.get_mobility_diff() / 5; + //value += (Value)pos.get_mobility_diff(); + //break; #endif /* EVALUATE_MOBILITY */ + value = (pos.piece_on_board_count(WHITE) - pos.piece_on_board_count(BLACK)) * VALUE_EACH_PIECE_ONBOARD; + switch (pos.get_action()) { case Action::select: case Action::place: diff --git a/src/mills.cpp b/src/mills.cpp index b49589dc..7e971fc0 100644 --- a/src/mills.cpp +++ b/src/mills.cpp @@ -423,6 +423,25 @@ void move_priority_list_shuffle() #endif } +bool is_star_squares_full(Position *pos) +{ + bool ret = false; + + if (rule.hasDiagonalLines) { + ret = (pos->get_board()[SQ_17] && + pos->get_board()[SQ_19] && + pos->get_board()[SQ_21] && + pos->get_board()[SQ_23]); + } else { + ret = (pos->get_board()[SQ_16] && + pos->get_board()[SQ_18] && + pos->get_board()[SQ_20] && + pos->get_board()[SQ_22]); + } + + return ret; +} + Depth get_search_depth(const Position *pos) { Depth d = 0; @@ -447,6 +466,12 @@ Depth get_search_depth(const Position *pos) const int index = rule.piecesCount * 2 - pos->count(WHITE) - pos->count(BLACK); d = placingDepthTable[index]; + + if (index == 4 && + is_star_squares_full((Position *)pos)) { + d = 1; // In order to use Mobility + } + if (d == 0) { return (Depth)gameOptions.getSkillLevel(); } else { diff --git a/src/search.cpp b/src/search.cpp index cdf9f453..13d2c556 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -382,6 +382,8 @@ Value search(Position *pos, Sanmill::Stack &ss, Depth depth, Depth ori epsilon = 0; } + //epsilon += pos->piece_to_remove_count(); + #ifdef PVS_AI if (i == 0) { if (after != before) {