Support clobber
authorianfab <ianfab@users.noreply.github.com>
Thu, 16 Aug 2018 20:55:26 +0000 (22:55 +0200)
committerianfab <ianfab@users.noreply.github.com>
Thu, 16 Aug 2018 20:56:35 +0000 (22:56 +0200)
https://en.wikipedia.org/wiki/Clobber

bench: 4737198

src/bitboard.cpp
src/position.cpp
src/position.h
src/types.h
src/variant.cpp
src/variant.h

index a722a73..8794578 100644 (file)
@@ -173,6 +173,7 @@ void Bitboards::init() {
       { -1, 1, 15, 17 }, // euroshogi knight
       { -8, -1, 1, 7, 8, 9 }, // gold
       { -8, -1, 1, 8 }, // horse
+      { -8, -1, 1, 8 }, // clobber
       { -9, -8, -7, -1, 1, 7, 8, 9 }, // commoner
       { -9, -8, -7, -1, 1, 7, 8, 9 } // king
   };
@@ -198,6 +199,7 @@ void Bitboards::init() {
       { -1, 1, 15, 17 }, // euroshogi knight
       { -8, -1, 1, 7, 8, 9 }, // gold
       { -8, -1, 1, 8 }, // horse
+      {}, // clobber
       { -9, -8, -7, -1, 1, 7, 8, 9 }, // commoner
       { -9, -8, -7, -1, 1, 7, 8, 9 } // king
   };
@@ -223,6 +225,7 @@ void Bitboards::init() {
     {}, // euroshogi knight
     {}, // gold
     { NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST }, // horse
+    {}, // clobber
     {}, // commoner
     {} // king
   };
@@ -248,6 +251,7 @@ void Bitboards::init() {
     {}, // euroshogi knight
     {}, // gold
     { NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST }, // horse
+    {}, // clobber
     {}, // commoner
     {} // king
   };
@@ -273,6 +277,7 @@ void Bitboards::init() {
     0, // euroshogi knight
     0, // gold
     7, // horse
+    0, // clobber
     0, // commoner
     0  // king
   };
@@ -298,6 +303,7 @@ void Bitboards::init() {
     0, // euroshogi knight
     0, // gold
     7, // horse
+    0, // clobber
     0, // commoner
     0  // king
   };
index 5ab0ca9..c2b40da 100644 (file)
@@ -705,7 +705,7 @@ bool Position::legal(Move m) const {
   }
 
   // no legal moves from target square
-  if ((type_of(m) == DROP || type_of(m) == NORMAL) && !(moves_bb(us, type_of(moved_piece(m)), to, 0) & board_bb()))
+  if (immobility_illegal() && (type_of(m) == DROP || type_of(m) == NORMAL) && !(moves_bb(us, type_of(moved_piece(m)), to, 0) & board_bb()))
       return false;
 
   // illegal drops
index 79c271a..7656a31 100644 (file)
@@ -108,6 +108,7 @@ public:
   bool drop_loop() const;
   bool captures_to_hand() const;
   bool first_rank_drops() const;
+  bool immobility_illegal() const;
   // winning conditions
   Value stalemate_value(int ply = 0) const;
   Value checkmate_value(int ply = 0) const;
@@ -352,6 +353,11 @@ inline bool Position::first_rank_drops() const {
   return var->firstRankDrops;
 }
 
+inline bool Position::immobility_illegal() const {
+  assert(var != nullptr);
+  return var->immobilityIllegal;
+}
+
 inline Value Position::stalemate_value(int ply) const {
   assert(var != nullptr);
   Value v = var->stalemateValue;
index aac7022..66874ac 100644 (file)
@@ -211,6 +211,7 @@ enum Value : int {
   EuroShogiKnightValueMg = 400,   EuroShogiKnightValueEg = 400,
   GoldValueMg            = 600,   GoldValueEg            = 600,
   HorseValueMg           = 1500,  HorseValueEg           = 1500,
+  ClobberPieceValueMg    = 300,   ClobberPieceValueEg    = 300,
   CommonerValueMg        = 600,   CommonerValueEg        = 600,
 
   MidgameLimit  = 15258, EndgameLimit  = 3915
@@ -221,7 +222,7 @@ const int PIECE_TYPE_BITS = 5; // PIECE_TYPE_NB = pow(2, PIECE_TYPE_BITS)
 enum PieceType {
   NO_PIECE_TYPE, PAWN, KNIGHT, BISHOP, ROOK,
   QUEEN, FERS, MET = FERS, ALFIL, SILVER, KHON = SILVER, AIWOK, BERS, DRAGON = BERS, CHANCELLOR,
-  AMAZON, KNIBIS, BISKNI, SHOGI_PAWN, LANCE, SHOGI_KNIGHT, EUROSHOGI_KNIGHT, GOLD, HORSE, COMMONER, KING,
+  AMAZON, KNIBIS, BISKNI, SHOGI_PAWN, LANCE, SHOGI_KNIGHT, EUROSHOGI_KNIGHT, GOLD, HORSE, CLOBBER_PIECE, COMMONER, KING,
   ALL_PIECES = 0,
 
   PIECE_TYPE_NB = 1 << PIECE_TYPE_BITS
index c0abfaf..f2e7e11 100644 (file)
@@ -253,6 +253,7 @@ void VariantMap::init() {
         v->promotedPieceType[BISHOP]           = HORSE;
         v->promotedPieceType[ROOK]             = DRAGON;
         v->mandatoryPiecePromotion = true;
+        v->immobilityIllegal = true;
         return v;
     } ();
     const Variant* judkinsshogi = [&]{
@@ -281,6 +282,7 @@ void VariantMap::init() {
         v->promotedPieceType[SILVER]       = GOLD;
         v->promotedPieceType[BISHOP]       = HORSE;
         v->promotedPieceType[ROOK]         = DRAGON;
+        v->immobilityIllegal = true;
         return v;
     } ();
     const Variant* minishogi = [&]{
@@ -307,6 +309,7 @@ void VariantMap::init() {
         v->promotedPieceType[SILVER]     = GOLD;
         v->promotedPieceType[BISHOP]     = HORSE;
         v->promotedPieceType[ROOK]       = DRAGON;
+        v->immobilityIllegal = true;
         return v;
     } ();
     const Variant* losalamos = [&]{
@@ -351,6 +354,20 @@ void VariantMap::init() {
         // TODO: illegal checkmates
         return v;
     } ();
+    const Variant* clobber = [&]{
+        Variant* v = new Variant();
+        v->maxRank = RANK_6;
+        v->maxFile = FILE_E;
+        v->reset_pieces();
+        v->add_piece(CLOBBER_PIECE, 'p');
+        v->startFen = "PpPpP/pPpPp/PpPpP/pPpPp/PpPpP/pPpPp w 0 1";
+        v->promotionPieceTypes = {};
+        v->doubleStep = false;
+        v->castling = false;
+        v->stalemateValue = -VALUE_MATE;
+        v->immobilityIllegal = false;
+        return v;
+    } ();
 
     // Add to UCI_Variant option
     add("chess", chess);
@@ -382,6 +399,7 @@ void VariantMap::init() {
     add("almost", almost);
     add("chigorin", chigorin);
     add("shatar", shatar);
+    add("clobber", clobber);
 }
 
 void VariantMap::add(std::string s, const Variant* v) {
index ec76193..6126673 100644 (file)
@@ -52,6 +52,7 @@ struct Variant {
   bool dropLoop = false;
   bool capturesToHand = false;
   bool firstRankDrops = false;
+  bool immobilityIllegal = false;
   // game end
   Value stalemateValue = VALUE_DRAW;
   Value checkmateValue = -VALUE_MATE;