mirror of
https://github.com/sockspls/badfish
synced 2025-05-03 01:59:36 +00:00
Fixed a bug that Learner::qsearch() recognizes stalemate as checkmated.
This commit is contained in:
parent
81262320c3
commit
89e846c476
4 changed files with 20 additions and 24 deletions
|
@ -502,15 +502,17 @@ void MultiThinkGenSfen::thread_worker(size_t thread_id)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 全駒されて詰んでいたりしないか?
|
if (pos.is_draw(ply)) {
|
||||||
if (pos.is_mated())
|
// Do not write if draw.
|
||||||
{
|
break;
|
||||||
if (pos.checkers()) {
|
|
||||||
// (この局面の一つ前の局面までは書き出す)
|
|
||||||
// Write the packed fens if checkmate.
|
|
||||||
// Do not write if stalemate.
|
|
||||||
flush_psv(-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 全駒されて詰んでいたりしないか?
|
||||||
|
if (MoveList<LEGAL>(pos).size() == 0)
|
||||||
|
{
|
||||||
|
// (この局面の一つ前の局面までは書き出す)
|
||||||
|
// Write the positions other than this position if checkmated.
|
||||||
|
flush_psv(-1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1965,7 +1967,8 @@ void LearnerThink::thread_worker(size_t thread_id)
|
||||||
// 全駒されて詰んでいる可能性がある。
|
// 全駒されて詰んでいる可能性がある。
|
||||||
// また宣言勝ちの局面はPVの指し手でleafに行けないので学習から除外しておく。
|
// また宣言勝ちの局面は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;
|
goto RetryRead;
|
||||||
|
|
||||||
// 読み込めたので試しに表示してみる。
|
// 読み込めたので試しに表示してみる。
|
||||||
|
|
|
@ -1483,12 +1483,3 @@ PieceNumber Position::piece_no_of(Square sq) const
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
#endif // defined(EVAL_NNUE)
|
#endif // defined(EVAL_NNUE)
|
||||||
|
|
||||||
#if defined(EVAL_LEARN)
|
|
||||||
// 現局面で指し手がないかをテストする。指し手生成ルーチンを用いるので速くない。探索中には使わないこと。
|
|
||||||
bool Position::is_mated() const
|
|
||||||
{
|
|
||||||
// 不成で詰めろを回避できるパターンはないのでLEGAL_ALLである必要はない。
|
|
||||||
return MoveList<LEGAL>(*this).size() == 0;
|
|
||||||
}
|
|
||||||
#endif // EVAL_LEARN
|
|
||||||
|
|
|
@ -192,9 +192,6 @@ public:
|
||||||
#endif // defined(EVAL_NNUE) || defined(EVAL_LEARN)
|
#endif // defined(EVAL_NNUE) || defined(EVAL_LEARN)
|
||||||
|
|
||||||
#if defined(EVAL_LEARN)
|
#if defined(EVAL_LEARN)
|
||||||
// 現局面で指し手がないかをテストする。指し手生成ルーチンを用いるので速くない。探索中には使わないこと。
|
|
||||||
bool is_mated() const;
|
|
||||||
|
|
||||||
// -- sfen化ヘルパ
|
// -- sfen化ヘルパ
|
||||||
|
|
||||||
// packされたsfenを得る。引数に指定したバッファに返す。
|
// packされたsfenを得る。引数に指定したバッファに返す。
|
||||||
|
|
|
@ -1854,21 +1854,26 @@ namespace Learner
|
||||||
{
|
{
|
||||||
Stack stack[MAX_PLY + 10], * ss = stack + 7;
|
Stack stack[MAX_PLY + 10], * ss = stack + 7;
|
||||||
Move pv[MAX_PLY + 1];
|
Move pv[MAX_PLY + 1];
|
||||||
std::vector<Move> pvs;
|
|
||||||
|
|
||||||
init_for_search(pos, ss);
|
init_for_search(pos, ss);
|
||||||
ss->pv = pv; // とりあえずダミーでどこかバッファがないといけない。
|
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 the mated value if checkmated.
|
||||||
return ValueAndPV(mated_in(/*ss->ply*/ 0 + 1), pvs);
|
return { mated_in(/*ss->ply*/ 0 + 1), {} };
|
||||||
}
|
}
|
||||||
|
|
||||||
auto bestValue = ::qsearch<PV>(pos, ss, -VALUE_INFINITE, VALUE_INFINITE, DEPTH_ZERO);
|
auto bestValue = ::qsearch<PV>(pos, ss, -VALUE_INFINITE, VALUE_INFINITE, DEPTH_ZERO);
|
||||||
|
|
||||||
// 得られたPVを返す。
|
// 得られたPVを返す。
|
||||||
|
std::vector<Move> pvs;
|
||||||
for (Move* p = &ss->pv[0]; is_ok(*p); ++p)
|
for (Move* p = &ss->pv[0]; is_ok(*p); ++p)
|
||||||
pvs.push_back(*p);
|
pvs.push_back(*p);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue