1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 17:19:36 +00:00

Fixed a bug that Learner::qsearch() recognizes stalemate as checkmated.

This commit is contained in:
Hisayori Noda 2019-07-04 23:44:58 +09:00
parent 81262320c3
commit 89e846c476
4 changed files with 20 additions and 24 deletions

View file

@ -502,15 +502,17 @@ void MultiThinkGenSfen::thread_worker(size_t thread_id)
break;
}
if (pos.is_draw(ply)) {
// Do not write if draw.
break;
}
// 全駒されて詰んでいたりしないか?
if (pos.is_mated())
if (MoveList<LEGAL>(pos).size() == 0)
{
if (pos.checkers()) {
// (この局面の一つ前の局面までは書き出す)
// Write the packed fens if checkmate.
// Do not write if stalemate.
flush_psv(-1);
}
// (この局面の一つ前の局面までは書き出す)
// Write the positions other than this position if checkmated.
flush_psv(-1);
break;
}
@ -1965,7 +1967,8 @@ void LearnerThink::thread_worker(size_t thread_id)
// 全駒されて詰んでいる可能性がある。
// また宣言勝ちの局面はPVの指し手でleafに行けないので学習から除外しておく。
// (そのような教師局面自体を書き出すべきではないのだが古い生成ルーチンで書き出しているかも知れないので)
if (pos.is_mated())
// Skip the position if there are no legal moves (=checkmated or stalemate).
if (MoveList<LEGAL>(pos).size() == 0)
goto RetryRead;
// 読み込めたので試しに表示してみる。

View file

@ -1483,12 +1483,3 @@ PieceNumber Position::piece_no_of(Square sq) const
return n;
}
#endif // defined(EVAL_NNUE)
#if defined(EVAL_LEARN)
// 現局面で指し手がないかをテストする。指し手生成ルーチンを用いるので速くない。探索中には使わないこと。
bool Position::is_mated() const
{
// 不成で詰めろを回避できるパターンはないのでLEGAL_ALLである必要はない。
return MoveList<LEGAL>(*this).size() == 0;
}
#endif // EVAL_LEARN

View file

@ -192,9 +192,6 @@ public:
#endif // defined(EVAL_NNUE) || defined(EVAL_LEARN)
#if defined(EVAL_LEARN)
// 現局面で指し手がないかをテストする。指し手生成ルーチンを用いるので速くない。探索中には使わないこと。
bool is_mated() const;
// -- sfen化ヘルパ
// packされたsfenを得る。引数に指定したバッファに返す。

View file

@ -1854,21 +1854,26 @@ namespace Learner
{
Stack stack[MAX_PLY + 10], * ss = stack + 7;
Move pv[MAX_PLY + 1];
std::vector<Move> pvs;
init_for_search(pos, ss);
ss->pv = pv; // とりあえずダミーでどこかバッファがないといけない。
if (pos.is_draw(0)) {
// Return draw value if draw.
return { VALUE_DRAW, {} };
}
// 詰まされているのか
if (pos.is_mated())
if (MoveList<LEGAL>(pos).size() == 0)
{
pvs.push_back(MOVE_NONE);
return ValueAndPV(mated_in(/*ss->ply*/ 0 + 1), pvs);
// Return the mated value if checkmated.
return { mated_in(/*ss->ply*/ 0 + 1), {} };
}
auto bestValue = ::qsearch<PV>(pos, ss, -VALUE_INFINITE, VALUE_INFINITE, DEPTH_ZERO);
// 得られたPVを返す。
std::vector<Move> pvs;
for (Move* p = &ss->pv[0]; is_ok(*p); ++p)
pvs.push_back(*p);