Skip to content

Commit

Permalink
Merge pull request official-stockfish#430 from ianfab/extinction
Browse files Browse the repository at this point in the history
Add support for extinction chess
  • Loading branch information
ddugovic authored Nov 1, 2017
2 parents 20b1c48 + a8bfa00 commit 8124134
Show file tree
Hide file tree
Showing 14 changed files with 424 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ ifneq ($(comp),mingw)
endif

### 3.2.1 Debugging
CXXFLAGS += -DANTI -DATOMIC -DBUGHOUSE -DCRAZYHOUSE -DHORDE -DKOTH -DLOOP -DLOSERS -DRACE -DSKILL -DSUICIDE -DTHREECHECK -DUSELONGESTPV
CXXFLAGS += -DANTI -DATOMIC -DBUGHOUSE -DCRAZYHOUSE -DEXTINCTION -DHORDE -DKOTH -DLOOP -DLOSERS -DRACE -DSKILL -DSUICIDE -DTHREECHECK -DUSELONGESTPV
ifneq (,$(filter -DBUGHOUSE,$(CXXFLAGS)))
ifeq (,$(filter -DCRAZYHOUSE,$(CXXFLAGS)))
$(error Crazyhouse (-DCRAZYHOUSE) is required for subvariant bughouse chess)
Expand Down
8 changes: 8 additions & 0 deletions src/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ const vector<string> Defaults[VARIANT_NB] = {
"2R5/3Q2pk/2p1p3/1pP1P1Qp/1P3P1P/p1P1B3/P7/1R2K3[NRBNPBPRNPBN] b - - 98 55",
},
#endif
#ifdef EXTINCTION
{
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
},
#endif
#ifdef HORDE
{
"rnbqkbnr/pppppppp/8/1PP2PP1/PPPPPPPP/PPPPPPPP/PPPPPPPP/PPPPPPPP w kq - 0 1",
Expand Down Expand Up @@ -260,6 +265,9 @@ const int defaultDepth[VARIANT_NB] = {
#ifdef CRAZYHOUSE
12,
#endif
#ifdef EXTINCTION
13,
#endif
#ifdef HORDE
13,
#endif
Expand Down
52 changes: 52 additions & 0 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,23 @@ namespace {
S( 111, 177), S( 115,181), S(124,197), S(124,199) }
},
#endif
#ifdef EXTINCTION
{
{ S(-126, -96), S(-103,-31), S(-90,-27), S(-40, 3), S( 0, 3), S( 4, 0), // Knights
S( 20, 12), S( 15, 33), S( 50, 46) },
{ S(-156, -79), S(-115,-43), S( 42,-14), S( 35, 26), S( 64, 26), S( 74, 38), // Bishops
S( 70, 46), S( 83, 71), S( 70, 68), S( 66, 80), S( 64, 68), S( 70, 77),
S( 97, 92), S( 89, 98) },
{ S( -53, -53), S( -22, -8), S(-48, 30), S(-14, 57), S( -4, 77), S( 11, 87), // Rooks
S( 7, 115), S( 12,123), S( 27,120), S( 6,140), S( 55,156), S( 18,161),
S( 51, 161), S( 54,171), S( 52,166) },
{ S( -26, -56), S( -24,-14), S( 7, 14), S( 8, 15), S( 18, 34), S( 14, 41), // Queens
S( 28, 58), S( 33, 66), S( 40, 70), S( 47, 74), S( 50,100), S( 52,106),
S( 59, 111), S( 50, 95), S( 60,115), S( 61,126), S( 75,144), S( 82,119),
S( 95, 137), S( 102,138), S(100,142), S(119,154), S(129,156), S(107,156),
S( 111, 177), S( 115,181), S(124,197), S(124,199) }
},
#endif
#ifdef HORDE
{
{ S(-126,-90), S( -7,-22), S( -46,-25), S( 19,7), S( -53, 71), S( 31, -1), // Knights
Expand Down Expand Up @@ -374,6 +391,12 @@ namespace {
{ V(27), V(13), V(19), V(111), V(140), V(203) }
},
#endif
#ifdef EXTINCTION
{
{ V(5), V( 5), V(31), V(73), V(166), V(252) },
{ V(7), V(14), V(38), V(73), V(166), V(252) }
},
#endif
#ifdef HORDE
{
{ V(-66), V(-25), V( 66), V(68), V( 72), V(250) },
Expand Down Expand Up @@ -496,6 +519,9 @@ namespace {
#ifdef CRAZYHOUSE
S(13, 20),
#endif
#ifdef EXTINCTION
S( 0, 0),
#endif
#ifdef HORDE
S( 7, 0),
#endif
Expand Down Expand Up @@ -540,6 +566,9 @@ namespace {
#ifdef CRAZYHOUSE
{ 0, 0, 112, 97, 61, 2 },
#endif
#ifdef EXTINCTION
{},
#endif
#ifdef HORDE
{ 0, 0, 78, 56, 45, 11 },
#endif
Expand Down Expand Up @@ -572,6 +601,9 @@ namespace {
#ifdef CRAZYHOUSE
{ 138, 362, 170, -595, -9, -1, 306 },
#endif
#ifdef EXTINCTION
{},
#endif
#ifdef HORDE
{ 101, 235, 134, -717, -11, -5, 0 },
#endif
Expand Down Expand Up @@ -618,6 +650,9 @@ namespace {
#ifdef CRAZYHOUSE
Value(12222),
#endif
#ifdef EXTINCTION
Value(12222),
#endif
#ifdef HORDE
VALUE_ZERO,
#endif
Expand Down Expand Up @@ -673,6 +708,17 @@ namespace {
b = attackedBy[Us][KING];
}
else
#endif
#ifdef EXTINCTION
if (pos.is_extinction())
{
attackedBy[Us][KING] = 0;
Bitboard kings = pos.pieces(Us, KING);
while (kings)
attackedBy[Us][KING] |= pos.attacks_from<KING>(pop_lsb(&kings));
b = attackedBy[Us][KING];
}
else
#endif
b = attackedBy[Us][KING] = pos.attacks_from<KING>(pos.square<KING>(Us));
attackedBy[Us][PAWN] = pe->pawn_attacks(Us);
Expand All @@ -684,6 +730,9 @@ namespace {
if ((
#ifdef ANTI
!pos.is_anti() &&
#endif
#ifdef EXTINCTION
!pos.is_extinction() &&
#endif
(pos.non_pawn_material(Them) >= RookValueMg + KnightValueMg))
#ifdef CRAZYHOUSE
Expand Down Expand Up @@ -1543,6 +1592,9 @@ namespace {
#ifdef ANTI
if (pos.is_anti()) {} else
#endif
#ifdef EXTINCTION
if (pos.is_extinction()) {} else
#endif
#ifdef RACE
if (pos.is_race()) {} else
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const Value Tempo[VARIANT_NB] = { // Must be visible to search
#ifdef CRAZYHOUSE
Value(100),
#endif
#ifdef EXTINCTION
Value(20),
#endif
#ifdef HORDE
Value(20),
#endif
Expand Down
24 changes: 24 additions & 0 deletions src/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ namespace {
{-198, -112, 83, 166, -160, -18 } // Queen
},
#endif
#ifdef EXTINCTION
{
// OUR PIECES
// pair pawn knight bishop rook queen
{1667 }, // Bishop pair
{ 40, 2 }, // Pawn
{ 32, 255, -3 }, // Knight OUR PIECES
{ 0, 104, 4, 0 }, // Bishop
{ -26, -2, 47, 105, -149 }, // Rook
{-185, 24, 122, 137, -134, 0 } // Queen
},
#endif
#ifdef HORDE
{
// OUR PIECES
Expand Down Expand Up @@ -214,6 +226,18 @@ namespace {
{ 75, 43, 20, 65, 221, 83 } // Queen
},
#endif
#ifdef EXTINCTION
{
// THEIR PIECES
// pair pawn knight bishop rook queen
{ 0 }, // Bishop pair
{ 36, 0 }, // Pawn
{ 9, 63, 0 }, // Knight OUR PIECES
{ 59, 65, 42, 0 }, // Bishop
{ 46, 39, 24, -24, 0 }, // Rook
{ 101, 100, -37, 141, 268, 0 } // Queen
},
#endif
#ifdef HORDE
{
// THEIR PIECES
Expand Down
42 changes: 42 additions & 0 deletions src/movegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ namespace {
#ifdef ANTI
if (V == ANTI_VARIANT)
kfrom = pos.castling_king_square(Cr);
#endif
#ifdef EXTINCTION
if (V == EXTINCTION_VARIANT)
kfrom = pos.castling_king_square(Cr);
#endif
Square rfrom = pos.castling_rook_square(Cr);
Square kto = relative_square(us, KingSide ? SQ_G1 : SQ_C1);
Expand All @@ -52,6 +56,10 @@ namespace {
#ifdef ANTI
if (V != ANTI_VARIANT)
{
#endif
#ifdef EXTINCTION
if (V != EXTINCTION_VARIANT)
{
#endif
for (Square s = kto; s != kfrom; s += K)
#ifdef ATOMIC
Expand All @@ -76,6 +84,9 @@ namespace {
#endif
return moveList;
}
#ifdef EXTINCTION
}
#endif
#ifdef ANTI
}
#endif
Expand Down Expand Up @@ -115,6 +126,10 @@ namespace {
*moveList++ = make<PROMOTION>(to - D, to, ROOK);
*moveList++ = make<PROMOTION>(to - D, to, BISHOP);
*moveList++ = make<PROMOTION>(to - D, to, KNIGHT);
#ifdef EXTINCTION
if (V == EXTINCTION_VARIANT)
*moveList++ = make<PROMOTION>(to - D, to, KING);
#endif
}

// Knight promotion is the only promotion that can give a direct check
Expand Down Expand Up @@ -396,6 +411,20 @@ namespace {
return moveList;
}
else
#endif
#ifdef EXTINCTION
if (V == EXTINCTION_VARIANT)
{
Bitboard kings = pos.pieces(Us, KING);
while (kings)
{
Square ksq = pop_lsb(&kings);
Bitboard b = pos.attacks_from<KING>(ksq) & target;
while (b)
*moveList++ = make_move(ksq, pop_lsb(&b));
}
}
else
#endif
if (Type != QUIET_CHECKS && Type != EVASIONS)
{
Expand Down Expand Up @@ -494,6 +523,11 @@ ExtMove* generate(const Position& pos, ExtMove* moveList) {
return us == WHITE ? generate_all<CRAZYHOUSE_VARIANT, WHITE, Type>(pos, moveList, target)
: generate_all<CRAZYHOUSE_VARIANT, BLACK, Type>(pos, moveList, target);
#endif
#ifdef EXTINCTION
if (pos.is_extinction())
return us == WHITE ? generate_all<EXTINCTION_VARIANT, WHITE, Type>(pos, moveList, target)
: generate_all<EXTINCTION_VARIANT, BLACK, Type>(pos, moveList, target);
#endif
#ifdef HORDE
if (pos.is_horde())
return us == WHITE ? generate_all<HORDE_VARIANT, WHITE, Type>(pos, moveList, target)
Expand Down Expand Up @@ -536,6 +570,10 @@ ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* moveList) {
if (pos.is_anti())
return moveList;
#endif
#ifdef EXTINCTION
if (pos.is_extinction())
return moveList;
#endif
#ifdef RACE
if (pos.is_race())
return moveList;
Expand Down Expand Up @@ -601,6 +639,10 @@ ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* moveList) {
if (pos.is_anti())
return moveList;
#endif
#ifdef EXTINCTION
if (pos.is_extinction())
return moveList;
#endif
#ifdef RACE
if (pos.is_race())
return moveList;
Expand Down
9 changes: 9 additions & 0 deletions src/pawns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ namespace {
{ V(154), V( 84), V( 87), V(188), V(105), V(177), V(275) } }
},
#endif
#ifdef EXTINCTION
{},
#endif
#ifdef HORDE
{
{ { V(100), V(20), V(10), V(46), V(82), V( 86), V( 98) }, // Not On King file
Expand Down Expand Up @@ -306,6 +309,9 @@ namespace {
{ V( -2), V( 61), V( 51), V( 56), V( -4) } }
},
#endif
#ifdef EXTINCTION
{},
#endif
#ifdef HORDE
{
{ { V(-11), V(-364), V(-337), V( 43), V( 69) }, // BlockedByKing
Expand Down Expand Up @@ -573,6 +579,9 @@ void init() {
#ifdef CRAZYHOUSE
{ 0, 8, 19, 13, 71, 94, 169, 324 },
#endif
#ifdef EXTINCTION
{ 0, 13, 24, 18, 76, 100, 175, 330 },
#endif
#ifdef HORDE
{ 37, 29, 3, 1, 105, 99, 343, 350 },
#endif
Expand Down
Loading

0 comments on commit 8124134

Please sign in to comment.