Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid repeating positions in Xiangqi (closes #101) #166

Merged
merged 1 commit into from
Jan 28, 2022
Merged
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
19 changes: 14 additions & 5 deletions engine/src/environments/fairy_state/fairyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ Key FairyBoard::hash_key() const {
}

bool FairyBoard::is_terminal() const {
// "Unlike in chess, in which stalemate is a draw, in xiangqi, it is a loss for the stalemated player."
// -- https://en.wikipedia.org/wiki/Xiangqi
if (this->number_repetitions() != 0) {
return true;
}
for (const ExtMove move : MoveList<LEGAL>(*this)) {
return false;
}
Expand All @@ -49,13 +54,17 @@ bool FairyBoard::is_terminal() const {

size_t FairyBoard::number_repetitions() const {
StateInfo *st = state();
if (st->repetition == 0) {
return 0;
}
else if (st->repetition) {
// st->repetition:
// "It is the ply distance from the previous
// occurrence of the same position, negative in the 3-fold case, or zero" -- fairy/position.cpp
// if the position was not repeated.
if (st->repetition > 0) {
return 1;
}
else return 0;
if (st->repetition < 0) {
return 2;
}
return 0;
}

Result get_result(const FairyBoard &pos, bool inCheck) {
Expand Down
12 changes: 8 additions & 4 deletions engine/src/environments/fairy_state/fairystate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ Action FairyState::uci_to_action(string &uciStr) const {

TerminalType FairyState::is_terminal(size_t numberLegalMoves, float &customTerminalValue) const {
if (numberLegalMoves == 0) {
if (board.checkers()) {
return TERMINAL_LOSS;
}
return TERMINAL_DRAW;
// "Unlike in chess, in which stalemate is a draw, in xiangqi, it is a loss for the stalemated player."
// -- https://en.wikipedia.org/wiki/Xiangqi
return TERMINAL_LOSS;
}
if (this->number_repetitions() != 0) {
// "If one side perpetually checks and the other side perpetually chases, the checking side has to stop or be ruled to have lost."
// -- https://en.wikipedia.org/wiki/Xiangqi
return TERMINAL_WIN;
}
return TERMINAL_NONE;
}
Expand Down
1 change: 1 addition & 0 deletions engine/src/uci/crazyara.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ void CrazyAra::init()
// This is a workaround for compatibility with Fairy-Stockfish
// Option with key "Threads" is also removed. (See /3rdparty/Fairy-Stockfish/src/ucioption.cpp)
Options.erase("Hash");
Options.erase("Use NNUE");
#endif
}

Expand Down