// n-move rule
if (n_move_rule() && st->rule50 > (2 * n_move_rule() - 1) && (!checkers() || MoveList<LEGAL>(*this).size()))
{
- result = VALUE_DRAW;
+ result = var->materialCounting ? convert_mate_value(material_counting_result(), ply) : VALUE_DRAW;
return true;
}
: var->perpetualCheckIllegal && perpetualUs ? -VALUE_MATE
: var->nFoldValueAbsolute && sideToMove == BLACK ? -var->nFoldValue
: var->nFoldValue, ply);
+ if (result == VALUE_DRAW && var->materialCounting)
+ result = convert_mate_value(material_counting_result(), ply);
return true;
}
// Check for bikjang rule (Janggi) and double passing
if (st->pliesFromNull > 0 && ((st->bikjang && st->previous->bikjang) || (st->pass && st->previous->pass)))
{
- result = var->materialCounting ? convert_mate_value(sideToMove == WHITE ? material_counting_result()
- : -material_counting_result(), ply)
- : VALUE_DRAW;
+ result = var->materialCounting ? convert_mate_value(material_counting_result(), ply) : VALUE_DRAW;
return true;
}
// Tsume mode: Assume that side with king wins when not in check
int end = captures_to_hand() ? st->pliesFromNull : std::min(st->rule50, st->pliesFromNull);
- if (end < 3 || var->nFoldValue != VALUE_DRAW || var->perpetualCheckIllegal)
+ if (end < 3 || var->nFoldValue != VALUE_DRAW || var->perpetualCheckIllegal || var->materialCounting)
return false;
Key originalKey = st->key;
inline Value Position::material_counting_result() const {
auto weigth_count = [this](PieceType pt, int v){ return v * (count(WHITE, pt) - count(BLACK, pt)); };
int materialCount;
+ Value result;
switch (var->materialCounting)
{
case JANGGI_MATERIAL:
+ weigth_count(WAZIR, 3)
+ weigth_count(SOLDIER, 2)
- 1;
- return materialCount > 0 ? VALUE_MATE : -VALUE_MATE;
+ result = materialCount > 0 ? VALUE_MATE : -VALUE_MATE;
+ break;
case UNWEIGHTED_MATERIAL:
- return count(WHITE, ALL_PIECES) > count(BLACK, ALL_PIECES) ? VALUE_MATE
- : count(WHITE, ALL_PIECES) < count(BLACK, ALL_PIECES) ? -VALUE_MATE
- : VALUE_DRAW;
+ result = count(WHITE, ALL_PIECES) > count(BLACK, ALL_PIECES) ? VALUE_MATE
+ : count(WHITE, ALL_PIECES) < count(BLACK, ALL_PIECES) ? -VALUE_MATE
+ : VALUE_DRAW;
+ break;
default:
assert(false);
- return VALUE_DRAW;
+ result = VALUE_DRAW;
}
+ return sideToMove == WHITE ? result : -result;
}
inline void Position::add_to_hand(Piece pc) {
v->diagonalLines = make_bitboard(SQ_D1, SQ_F1, SQ_E2, SQ_D3, SQ_F3,
SQ_D8, SQ_F8, SQ_E9, SQ_D10, SQ_F10);
v->kingPass = true;
- v->nFoldValue = -VALUE_MATE;
+ v->nFoldValue = VALUE_DRAW;
v->perpetualCheckIllegal = true;
return v;
}