Skip to content

Commit

Permalink
MovePickerで進行度を使用してみる
Browse files Browse the repository at this point in the history
  • Loading branch information
tttak committed Nov 16, 2016
1 parent 1a895f7 commit 798c0b5
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
26 changes: 19 additions & 7 deletions src/movepick.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,18 +309,23 @@ void MovePicker::ScoreMoves<kQuiets>() {

Color c = pos_.side_to_move();

// 進行度
double progress = ss_->progress;
//std::printf("progress=%f\n", progress);

for (ExtMove* it = moves_.begin(); it != end_; ++it) {
Move move = it->move;
Piece pc = move.piece_after_move();
Square sq = move.to();

//it->score = history_[it->move];
it->score = history_[move]
+ sf_history[pc][sq]
+ (cm ? (*cm)[pc][sq] : kScoreZero)
+ (fm ? (*fm)[pc][sq] : kScoreZero)
+ (f2 ? (*f2)[pc][sq] : kScoreZero)
+ from_to.get(c, move);
+ (sf_history[pc][sq]
+ (cm ? (*cm)[pc][sq] : kScoreZero)
+ (fm ? (*fm)[pc][sq] : kScoreZero)
+ (f2 ? (*f2)[pc][sq] : kScoreZero)
+ from_to.get(c, move)
) * (1 - progress);
}
}

Expand All @@ -332,6 +337,12 @@ void MovePicker::ScoreMoves<kEvasions>() {

Color c = pos_.side_to_move();

// 進行度
double progress = 0;
if (ss_) {
progress = ss_->progress;
}

for (ExtMove* it = moves_.begin(); it != end_; ++it) {
Move move = it->move;
Piece pc = move.piece_after_move();
Expand All @@ -348,8 +359,9 @@ void MovePicker::ScoreMoves<kEvasions>() {
// Stockfish7対応
//it->score = history_[move];
it->score = history_[move]
+ sf_history[pc][move.to()]
+ from_to.get(c, move);
+ (sf_history[pc][move.to()]
+ from_to.get(c, move)
) * (1 - progress);
}
}
}
Expand Down
31 changes: 28 additions & 3 deletions src/search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,11 @@ void Search::Init() {

// Stockfish7対応
for (int d = 0; d < 16; ++d) {
// TODO 読み太1.7を参考に
FutilityMoveCounts[0][d] = int(2.4 + 0.773 * pow(d + 0.00, 1.8));
FutilityMoveCounts[1][d] = int(2.9 + 1.045 * pow(d + 0.49, 1.8));
//FutilityMoveCounts[0][d] = int(12.4 + 0.773 * pow(d + 0.00, 1.8));
//FutilityMoveCounts[1][d] = int(12.9 + 1.045 * pow(d + 0.49, 1.8));
}

}
Expand Down Expand Up @@ -470,7 +473,7 @@ Score Search::MainSearch(Node& node, Score alpha, Score beta, const Depth depth,
if (shared_.signals.stop) {
return kScoreDraw;
} else if (ply >= kMaxPly) {
return !in_check ? node.Evaluate() : kScoreDraw;
return !in_check ? node.Evaluate(&ss->progress) : kScoreDraw;
}

// 千日手等を検出する
Expand Down Expand Up @@ -526,7 +529,7 @@ Score Search::MainSearch(Node& node, Score alpha, Score beta, const Depth depth,
}

// 評価関数を呼ぶ
eval = node.Evaluate(); // 差分計算を行うため、常に評価関数を呼ぶ
eval = node.Evaluate(&ss->progress); // 差分計算を行うため、常に評価関数を呼ぶ
if (in_check) {
ss->static_score = kScoreNone;
goto moves_loop;
Expand Down Expand Up @@ -790,12 +793,23 @@ Score Search::MainSearch(Node& node, Score alpha, Score beta, const Depth depth,
&& best_score > kScoreMatedInMaxPly) {

// Move count based pruning
// TODO Stockfish7対応
#if 1
if ( depth < 16 * kOnePly
&& move_count >= futility_move_count(kIsPv, depth)
&& gains_[move] < kScoreZero
&& history_.HasNegativeScore(move)) {
continue;
}
#endif

#if 0
if ( moveCountPruning
&& gains_[move] < kScoreZero
&& history_.HasNegativeScore(move)) {
continue;
}
#endif

Depth r = reduction<kIsPv>(improving, depth, move_count);
Depth predicted_depth = new_depth - r;
Expand Down Expand Up @@ -1058,7 +1072,7 @@ Score Search::QuiecenceSearch(Node& node, Score alpha, Score beta,

// 最大手数に到達したら、探索を打ち切る
if (ply >= kMaxPly) {
return !kInCheck ? node.Evaluate() : kScoreDraw;
return !kInCheck ? node.Evaluate(&ss->progress) : kScoreDraw;
}

// 千日手等を検出する
Expand Down Expand Up @@ -1098,6 +1112,10 @@ Score Search::QuiecenceSearch(Node& node, Score alpha, Score beta,
if (kInCheck) {
node.Evaluate(&progress); // 差分計算を行うため、常に評価関数を呼ぶ
ss->static_score = kScoreNone;

// 進行度
ss->progress = progress;

} else {
// 1手詰関数を呼ぶ
if (IsMateInOnePly(node, &ss->current_move)) {
Expand All @@ -1111,6 +1129,10 @@ Score Search::QuiecenceSearch(Node& node, Score alpha, Score beta,
if (tte != nullptr) {
// 静的評価値をセットする
ss->static_score = best_score = node.Evaluate(&progress);

// 進行度
ss->progress = progress;

// 置換表の得点のほうが、静的評価値よりも信頼できる場合は、静的評価値を置換表の得点で置き換える
if (!learning_mode_ && hash_score != kScoreNone) {
if (tte->bound() & (hash_score > best_score ? kBoundLower : kBoundUpper)) {
Expand All @@ -1119,6 +1141,9 @@ Score Search::QuiecenceSearch(Node& node, Score alpha, Score beta,
}
} else {
ss->static_score = best_score = node.Evaluate(&progress);

// 進行度
ss->progress = progress;
}

// stand pat(何も手を指さなくてもβ値を上回る場合は、ここでfail-highする)
Expand Down
3 changes: 3 additions & 0 deletions src/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class Search {
// Stockfish7対応
CounterMoveStats* counterMoves;
int moveCount;

// 進行度
double progress;
};

static void Init();
Expand Down
2 changes: 1 addition & 1 deletion src/usi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

namespace {

const auto kProgramName = "Gikou Stockfish7 20161030";
const auto kProgramName = "Gikou Kai 20161116";
const auto kAuthorName = "Yosuke Demura";
const auto kBookFile = "book.bin";

Expand Down

0 comments on commit 798c0b5

Please sign in to comment.