Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/datagen/datagen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace stoat::datagen {
const auto sennichite = newPos.testSennichite(false, keyHistory);
keyHistory.pop_back();

if (sennichite != SennichiteStatus::kWin) {
if (sennichite != SennichiteStatus::kWin || sennichite != SennichiteStatus::kLose) {
return move;
}

Expand Down Expand Up @@ -240,7 +240,7 @@ namespace stoat::datagen {
if (sennichite == SennichiteStatus::kDraw) {
outcome = format::Outcome::kDraw;
break;
} else if (sennichite == SennichiteStatus::kWin) {
} else if (sennichite == SennichiteStatus::kWin || sennichite == SennichiteStatus::kLose) {
const std::scoped_lock lock{s_printMutex};

auto& errStream = getErrStream(outDir);
Expand Down
14 changes: 10 additions & 4 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,20 +300,26 @@ namespace stoat {

SennichiteStatus Position::testSennichite(bool cuteChessWorkaround, std::span<const u64> keyHistory, i32 limit)
const {
const auto end = std::max(0, static_cast<i32>(keyHistory.size()) - limit - 1);
const auto end = std::min(static_cast<i32>(keyHistory.size()), limit);

i32 repetitions = 1;

for (i32 i = static_cast<i32>(keyHistory.size()) - 4; i >= end; i -= 2) {
if (keyHistory[i] == key()) {
for (i32 i = 4; i <= end; i += 2) {
if (keyHistory[keyHistory.size() - i] == key()) {
--repetitions;
if (repetitions == 0) {
// Older cutechess versions do not handle perpetuals
// properly - work around that to avoid illegal moves
if (cuteChessWorkaround) {
return isInCheck() ? SennichiteStatus::kWin : SennichiteStatus::kDraw;
} else {
return m_consecutiveChecks[stm().idx()] >= 2 ? SennichiteStatus::kWin : SennichiteStatus::kDraw;
if (i / 2 <= m_consecutiveChecks[stm().idx()]) {
return SennichiteStatus::kWin;
} else if (i / 2 <= m_consecutiveChecks[stm().flip().idx()]) {
return SennichiteStatus::kLose;
} else {
return SennichiteStatus::kDraw;
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ namespace stoat {
enum class SennichiteStatus {
kNone = 0,
kDraw,
kWin, // perpetual check by opponent
kWin, // perpetual check by opponent
kLose, // perpetual check
};

namespace eval::nnue {
Expand Down
10 changes: 7 additions & 3 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,13 @@ namespace stoat {
Score score;

if (sennichite == SennichiteStatus::kWin) {
// illegal perpetual
--legalMoves;
continue;
} else if (sennichite == SennichiteStatus::kDraw) {
} else if (sennichite == SennichiteStatus::kLose) {
score = kScoreMate - ply - 1;
goto skipSearch;
}
else if (sennichite == SennichiteStatus::kDraw) {
score = drawScore(thread.loadNodes());
goto skipSearch;
} else if (pos.isEnteringKingsWin()) {
Expand Down Expand Up @@ -776,8 +779,9 @@ namespace stoat {
Score score;

if (sennichite == SennichiteStatus::kWin) {
// illegal perpetual
continue;
} else if (sennichite == SennichiteStatus::kLose) {
score = kScoreMate - ply - 1;
} else if (sennichite == SennichiteStatus::kDraw) {
score = drawScore(thread.loadNodes());
} else {
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.100
0.1.101