Support horde chess
authorianfab <ianfab@users.noreply.github.com>
Tue, 14 Aug 2018 20:31:48 +0000 (22:31 +0200)
committerianfab <ianfab@users.noreply.github.com>
Tue, 14 Aug 2018 20:31:48 +0000 (22:31 +0200)
- Add horde chess.
- Increase piece list size.
- Add configuration option for pawn double steps from first rank.

No functional change for existing variants.

src/movegen.cpp
src/position.cpp
src/position.h
src/variant.cpp
src/variant.h
tests/perft.sh

index ba1656c..4f80959 100644 (file)
@@ -111,12 +111,16 @@ namespace {
     // Compute our parametrized parameters at compile time, named according to
     // the point of view of white side.
     constexpr Color     Them     = (Us == WHITE ? BLACK      : WHITE);
-    constexpr Bitboard  TRank3BB = (Us == WHITE ? Rank3BB    : Rank6BB);
     constexpr Direction Up       = (Us == WHITE ? NORTH      : SOUTH);
     constexpr Direction Down     = (Us == WHITE ? SOUTH      : NORTH);
     constexpr Direction UpRight  = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
     constexpr Direction UpLeft   = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
 
+    // Define squares a pawn can pass during a double step
+    Bitboard  TRank3BB = rank_bb(relative_rank(Us, RANK_3, pos.max_rank()));
+    if (pos.first_rank_double_steps())
+        TRank3BB |= rank_bb(relative_rank(Us, RANK_2, pos.max_rank()));
+
     Bitboard emptySquares;
 
     Bitboard TRank8BB = rank_bb(Us == WHITE ? pos.promotion_rank() : Rank(pos.max_rank() - pos.promotion_rank()));
index c190358..5ab0ca9 100644 (file)
@@ -1032,6 +1032,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
   {
       // Set en-passant square if the moved pawn can be captured
       if (   (int(to) ^ int(from)) == 16
+          && relative_rank(us, rank_of(from), max_rank()) == RANK_2
           && (attacks_from<PAWN>(us, to - pawn_push(us)) & pieces(them, PAWN)))
       {
           st->epSquare = to - pawn_push(us);
index 650d8be..79c271a 100644 (file)
@@ -100,6 +100,7 @@ public:
   bool mandatory_piece_promotion() const;
   bool endgame_eval() const;
   bool double_step_enabled() const;
+  bool first_rank_double_steps() const;
   bool castling_enabled() const;
   bool checking_permitted() const;
   bool must_capture() const;
@@ -227,7 +228,7 @@ private:
   Bitboard byTypeBB[PIECE_TYPE_NB];
   Bitboard byColorBB[COLOR_NB];
   int pieceCount[PIECE_NB];
-  Square pieceList[PIECE_NB][16];
+  Square pieceList[PIECE_NB][64];
   int index[SQUARE_NB];
   int castlingRightsMask[SQUARE_NB];
   Square castlingRookSquare[CASTLING_RIGHT_NB];
@@ -311,6 +312,11 @@ inline bool Position::double_step_enabled() const {
   return var->doubleStep;
 }
 
+inline bool Position::first_rank_double_steps() const {
+  assert(var != nullptr);
+  return var->firstRankDoubleSteps;
+}
+
 inline bool Position::castling_enabled() const {
   assert(var != nullptr);
   return var->castling;
index 991618f..c0abfaf 100644 (file)
@@ -178,6 +178,14 @@ void VariantMap::init() {
         v->extinctionPieceTypes = {PAWN};
         return v;
     } ();
+    const Variant* horde = [&]{
+        Variant* v = new Variant();
+        v->startFen = "rnbqkbnr/pppppppp/8/1PP2PP1/PPPPPPPP/PPPPPPPP/PPPPPPPP/PPPPPPPP w kq - 0 1";
+        v->firstRankDoubleSteps = true;
+        v->extinctionValue = -VALUE_MATE;
+        v->extinctionPieceTypes = {ALL_PIECES};
+        return v;
+    } ();
     const Variant* threecheck = [&]{
         Variant* v = new Variant();
         v->startFen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 3+3 0 1";
@@ -360,6 +368,7 @@ void VariantMap::init() {
     add("antichess", antichess);
     add("extinction", extinction);
     add("kinglet", kinglet);
+    add("horde", horde);
     add("3check", threecheck);
     add("5check", fivecheck);
     add("crazyhouse", crazyhouse);
index 2c93f5a..ec76193 100644 (file)
@@ -44,6 +44,7 @@ struct Variant {
   bool mandatoryPiecePromotion = false;
   bool endgameEval = false;
   bool doubleStep = true;
+  bool firstRankDoubleSteps = false;
   bool castling = true;
   bool checking = true;
   bool mustCapture = false;
index 60bcee1..981f2cc 100755 (executable)
@@ -46,6 +46,7 @@ expect perft.exp asean startpos 5 6223994 > /dev/null
 expect perft.exp ai-wok startpos 5 13275068 > /dev/null
 expect perft.exp euroshogi startpos 5 9451149 > /dev/null
 expect perft.exp minishogi startpos 5 533203 > /dev/null
+expect perft.exp horde startpos 6 5396554 > /dev/null
 
 rm perft.exp