Skip to content

Commit

Permalink
Lone horde piece versus king is usually drawn
Browse files Browse the repository at this point in the history
  • Loading branch information
ddugovic committed Jun 22, 2019
1 parent 8b54fe1 commit 9e76c3e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/endgame.cpp
Expand Up @@ -351,6 +351,18 @@ Value Endgame<CHESS_VARIANT, KNNKP>::operator()(const Position& pos) const {
template<> Value Endgame<CHESS_VARIANT, KNNK>::operator()(const Position&) const { return VALUE_DRAW; }


// Any vs K is drawn except for cornered N vs K (not checked).
#ifdef HORDE
template<>
ScaleFactor Endgame<HORDE_VARIANT, AK>::operator()(const Position& pos) const {

assert(pos.variant() == HORDE_VARIANT);
assert(pos.count<ALL_PIECES>(strongSide) == 1);
assert(pos.count<ALL_PIECES>(weakSide) == 1);
return SCALE_FACTOR_DRAW;
}
#endif

/// KB and one or more pawns vs K. It checks for draws with rook pawns and
/// a bishop of the wrong color. If such a draw is detected, SCALE_FACTOR_DRAW
/// is returned. If not, the return value is SCALE_FACTOR_NONE, i.e. no scaling
Expand Down
3 changes: 3 additions & 0 deletions src/endgame.h
Expand Up @@ -59,6 +59,9 @@ enum EndgameCode {
KQKR, // KQ vs KR

SCALING_FUNCTIONS,
#ifdef HORDE
AK, // Any vs K
#endif
KBPsK, // KB and pawns vs K
KQKRPs, // KQ vs KR and pawns
KRPKR, // KRP vs KR
Expand Down
15 changes: 14 additions & 1 deletion src/material.cpp
Expand Up @@ -357,6 +357,9 @@ namespace {
Endgame<ATOMIC_VARIANT, KXK> EvaluateAtomicKXK[] = { Endgame<ATOMIC_VARIANT, KXK>(WHITE), Endgame<ATOMIC_VARIANT, KXK>(BLACK) };
#endif

#ifdef HORDE
Endgame<HORDE_VARIANT, AK> ScaleHordeAK[] = { Endgame<HORDE_VARIANT, AK>(WHITE), Endgame<HORDE_VARIANT, AK>(BLACK) };
#endif
Endgame<CHESS_VARIANT, KBPsK> ScaleKBPsK[] = { Endgame<CHESS_VARIANT, KBPsK>(WHITE), Endgame<CHESS_VARIANT, KBPsK>(BLACK) };
Endgame<CHESS_VARIANT, KQKRPs> ScaleKQKRPs[] = { Endgame<CHESS_VARIANT, KQKRPs>(WHITE), Endgame<CHESS_VARIANT, KQKRPs>(BLACK) };
Endgame<CHESS_VARIANT, KPsK> ScaleKPsK[] = { Endgame<CHESS_VARIANT, KPsK>(WHITE), Endgame<CHESS_VARIANT, KPsK>(BLACK) };
Expand Down Expand Up @@ -520,8 +523,9 @@ Entry* probe(const Position& pos) {
return e;
}

if (pos.variant() == CHESS_VARIANT)
switch (pos.variant())
{
case CHESS_VARIANT:
// We didn't find any specialized scaling function, so fall back on generic
// ones that refer to more than one material distribution. Note that in this
// case we don't return after setting the function.
Expand Down Expand Up @@ -567,6 +571,15 @@ Entry* probe(const Position& pos) {
if (!pos.count<PAWN>(BLACK) && npm_b - npm_w <= BishopValueMg)
e->factor[BLACK] = uint8_t(npm_b < RookValueMg ? SCALE_FACTOR_DRAW :
npm_w <= BishopValueMg ? 4 : 14);
break;
#ifdef HORDE
case HORDE_VARIANT:
for (Color c = WHITE; c <= BLACK; ++c)
if (pos.is_horde_color(c) && pos.count<ALL_PIECES>() == 2)
e->scalingFunction[c] = &ScaleHordeAK[c];
break;
#endif
default: break;
}

// Evaluate the material imbalance. We use PIECE_TYPE_NONE as a place holder
Expand Down

1 comment on commit 9e76c3e

@ddugovic
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#494 comes first of course.

This WIP horde patch is a fun idea for a rainy day.

Please sign in to comment.