Support Grasshopper
authorFabian Fichter <ianfab@users.noreply.github.com>
Sat, 1 May 2021 10:18:06 +0000 (12:18 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sat, 1 May 2021 11:54:22 +0000 (13:54 +0200)
Credits to @yoav-rozin for the initial implementation.

Closes #292.

AUTHORS
src/bitboard.cpp
src/bitboard.h
src/magic.h
src/types.h
src/variants.ini

diff --git a/AUTHORS b/AUTHORS
index 2dcfbb4..310e647 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -9,6 +9,7 @@ Fulmene
 gbtami
 QueensGambit
 tttak
+yoav-rozin
 ydirson
 
 
index 5bafcb9..71e021f 100644 (file)
@@ -47,9 +47,13 @@ Magic ElephantMagics[SQUARE_NB];
 Magic JanggiElephantMagics[SQUARE_NB];
 Magic CannonDiagMagics[SQUARE_NB];
 Magic NightriderMagics[SQUARE_NB];
+Magic GrasshopperMagicsH[SQUARE_NB];
+Magic GrasshopperMagicsV[SQUARE_NB];
+Magic GrasshopperMagicsD[SQUARE_NB];
 
 Magic* magics[] = {BishopMagics, RookMagicsH, RookMagicsV, CannonMagicsH, CannonMagicsV,
-                   HorseMagics, ElephantMagics, JanggiElephantMagics, CannonDiagMagics, NightriderMagics};
+                   HorseMagics, ElephantMagics, JanggiElephantMagics, CannonDiagMagics, NightriderMagics,
+                   GrasshopperMagicsH, GrasshopperMagicsV, GrasshopperMagicsD};
 
 namespace {
 
@@ -66,6 +70,9 @@ namespace {
   Bitboard JanggiElephantTable[0x1C000];  // To store janggi elephant attacks
   Bitboard CannonDiagTable[0x33C00]; // To store diagonal cannon attacks
   Bitboard NightriderTable[0x70200]; // To store nightrider attacks
+  Bitboard GrasshopperTableH[0x11800];  // To store horizontal grasshopper attacks
+  Bitboard GrasshopperTableV[0x4800];  // To store vertical grasshopper attacks
+  Bitboard GrasshopperTableD[0x33C00]; // To store diagonal grasshopper attacks
 #else
   Bitboard RookTableH[0xA00];  // To store horizontal rook attacks
   Bitboard RookTableV[0xA00];  // To store vertical rook attacks
@@ -77,6 +84,9 @@ namespace {
   Bitboard JanggiElephantTable[0x5C00];  // To store janggi elephant attacks
   Bitboard CannonDiagTable[0x1480]; // To store diagonal cannon attacks
   Bitboard NightriderTable[0x1840]; // To store nightrider attacks
+  Bitboard GrasshopperTableH[0xA00];  // To store horizontal grasshopper attacks
+  Bitboard GrasshopperTableV[0xA00];  // To store vertical grasshopper attacks
+  Bitboard GrasshopperTableD[0x1480]; // To store diagonal grasshopper attacks
 #endif
 
   // Rider directions
@@ -90,8 +100,11 @@ namespace {
                                                             {EAST  + 2 * SOUTH_EAST, 0}, {SOUTH + 2 * SOUTH_EAST, 0},
                                                             {SOUTH + 2 * SOUTH_WEST, 0}, {WEST  + 2 * SOUTH_WEST, 0},
                                                             {WEST  + 2 * NORTH_WEST, 0}, {NORTH + 2 * NORTH_WEST, 0} };
+  const std::map<Direction, int> GrasshopperDirectionsV { {NORTH, 1}, {SOUTH, 1}};
+  const std::map<Direction, int> GrasshopperDirectionsH { {EAST, 1}, {WEST, 1} };
+  const std::map<Direction, int> GrasshopperDirectionsD { {NORTH_EAST, 1}, {SOUTH_EAST, 1}, {SOUTH_WEST, 1}, {NORTH_WEST, 1} };
 
-  enum MovementType { RIDER, HOPPER, LAME_LEAPER };
+  enum MovementType { RIDER, HOPPER, LAME_LEAPER, UNLIMITED_RIDER };
 
   template <MovementType MT>
 #ifdef PRECOMPUTED_MAGICS
@@ -117,7 +130,7 @@ namespace {
             if (MT != HOPPER || hurdle)
             {
                 attack |= s;
-                if (limit && ++count >= limit)
+                if (limit && MT != UNLIMITED_RIDER && ++count >= limit)
                     break;
             }
 
@@ -241,12 +254,12 @@ void Bitboards::init_pieces() {
           }
           for (auto const& [d, limit] : pi->hopper[modality])
           {
-              if (!limit && RookDirectionsH.find(d) != RookDirectionsH.end())
-                  riderTypes |= RIDER_CANNON_H;
-              if (!limit && RookDirectionsV.find(d) != RookDirectionsV.end())
-                  riderTypes |= RIDER_CANNON_V;
-              if (!limit && BishopDirections.find(d) != BishopDirections.end())
-                  riderTypes |= RIDER_CANNON_DIAG;
+              if (RookDirectionsH.find(d) != RookDirectionsH.end())
+                  riderTypes |= limit == 1 ? RIDER_GRASSHOPPER_H : RIDER_CANNON_H;
+              if (RookDirectionsV.find(d) != RookDirectionsV.end())
+                  riderTypes |= limit == 1 ? RIDER_GRASSHOPPER_V : RIDER_CANNON_V;
+              if (BishopDirections.find(d) != BishopDirections.end())
+                  riderTypes |= limit == 1 ? RIDER_GRASSHOPPER_D : RIDER_CANNON_DIAG;
           }
       }
 
@@ -268,7 +281,7 @@ void Bitboards::init_pieces() {
                           leaper |= safe_destination(s, c == WHITE ? d : -d);
                   }
                   pseudo |= sliding_attack<RIDER>(pi->slider[modality], s, 0, c);
-                  pseudo |= sliding_attack<RIDER>(pi->hopper[modality], s, 0, c);
+                  pseudo |= sliding_attack<UNLIMITED_RIDER>(pi->hopper[modality], s, 0, c);
               }
           }
       }
@@ -306,6 +319,9 @@ void Bitboards::init() {
   init_magics<LAME_LEAPER>(JanggiElephantTable, JanggiElephantMagics, JanggiElephantDirections, JanggiElephantMagicInit);
   init_magics<HOPPER>(CannonDiagTable, CannonDiagMagics, BishopDirections, CannonDiagMagicInit);
   init_magics<RIDER>(NightriderTable, NightriderMagics, HorseDirections, NightriderMagicInit);
+  init_magics<HOPPER>(GrasshopperTableH, GrasshopperMagicsH, GrasshopperDirectionsH, GrasshopperMagicHInit);
+  init_magics<HOPPER>(GrasshopperTableV, GrasshopperMagicsV, GrasshopperDirectionsV, GrasshopperMagicVInit);
+  init_magics<HOPPER>(GrasshopperTableD, GrasshopperMagicsD, GrasshopperDirectionsD, GrasshopperMagicDInit);
 #else
   init_magics<RIDER>(RookTableH, RookMagicsH, RookDirectionsH);
   init_magics<RIDER>(RookTableV, RookMagicsV, RookDirectionsV);
@@ -317,6 +333,9 @@ void Bitboards::init() {
   init_magics<LAME_LEAPER>(JanggiElephantTable, JanggiElephantMagics, JanggiElephantDirections);
   init_magics<HOPPER>(CannonDiagTable, CannonDiagMagics, BishopDirections);
   init_magics<RIDER>(NightriderTable, NightriderMagics, HorseDirections);
+  init_magics<HOPPER>(GrasshopperTableH, GrasshopperMagicsH, GrasshopperDirectionsH);
+  init_magics<HOPPER>(GrasshopperTableV, GrasshopperMagicsV, GrasshopperDirectionsV);
+  init_magics<HOPPER>(GrasshopperTableD, GrasshopperMagicsD, GrasshopperDirectionsD);
 #endif
 
   init_pieces();
@@ -362,7 +381,6 @@ namespace {
     int* epoch = new int[1 << (FILE_NB + RANK_NB - 4)]();
     int cnt = 0, size = 0;
 
-
     for (Square s = SQ_A1; s <= SQ_MAX; ++s)
     {
         // Board edges are not considered in the relevant occupancies
@@ -374,7 +392,8 @@ namespace {
         // the number of 1s of the mask. Hence we deduce the size of the shift to
         // apply to the 64 or 32 bits word to get the index.
         Magic& m = magics[s];
-        m.mask  = (MT == LAME_LEAPER ? lame_leaper_path(directions, s) : sliding_attack<MT == HOPPER ? RIDER : MT>(directions, s, 0)) & ~edges;
+        // The mask for hoppers is unlimited distance, even if the hopper is limited distance (e.g., grasshopper)
+        m.mask  = (MT == LAME_LEAPER ? lame_leaper_path(directions, s) : sliding_attack<MT == HOPPER ? UNLIMITED_RIDER : MT>(directions, s, 0)) & ~edges;
 #ifdef LARGEBOARDS
         m.shift = 128 - popcount(m.mask);
 #else
index 232c4f5..15ebc79 100644 (file)
@@ -149,6 +149,9 @@ extern Magic ElephantMagics[SQUARE_NB];
 extern Magic JanggiElephantMagics[SQUARE_NB];
 extern Magic CannonDiagMagics[SQUARE_NB];
 extern Magic NightriderMagics[SQUARE_NB];
+extern Magic GrasshopperMagicsH[SQUARE_NB];
+extern Magic GrasshopperMagicsV[SQUARE_NB];
+extern Magic GrasshopperMagicsD[SQUARE_NB];
 
 extern Magic* magics[];
 
@@ -384,7 +387,8 @@ template<RiderType R>
 inline Bitboard rider_attacks_bb(Square s, Bitboard occupied) {
 
   assert(R == RIDER_BISHOP || R == RIDER_ROOK_H || R == RIDER_ROOK_V || R == RIDER_CANNON_H || R == RIDER_CANNON_V
-         || R == RIDER_HORSE || R == RIDER_ELEPHANT || R == RIDER_JANGGI_ELEPHANT || R == RIDER_CANNON_DIAG || R == RIDER_NIGHTRIDER);
+         || R == RIDER_HORSE || R == RIDER_ELEPHANT || R == RIDER_JANGGI_ELEPHANT || R == RIDER_CANNON_DIAG || R == RIDER_NIGHTRIDER
+         || R == RIDER_GRASSHOPPER_H || R == RIDER_GRASSHOPPER_V || R == RIDER_GRASSHOPPER_D);
   const Magic& m =  R == RIDER_ROOK_H ? RookMagicsH[s]
                   : R == RIDER_ROOK_V ? RookMagicsV[s]
                   : R == RIDER_CANNON_H ? CannonMagicsH[s]
@@ -394,6 +398,9 @@ inline Bitboard rider_attacks_bb(Square s, Bitboard occupied) {
                   : R == RIDER_JANGGI_ELEPHANT ? JanggiElephantMagics[s]
                   : R == RIDER_CANNON_DIAG ? CannonDiagMagics[s]
                   : R == RIDER_NIGHTRIDER ? NightriderMagics[s]
+                  : R == RIDER_GRASSHOPPER_H ? GrasshopperMagicsH[s]
+                  : R == RIDER_GRASSHOPPER_V ? GrasshopperMagicsV[s]
+                  : R == RIDER_GRASSHOPPER_D ? GrasshopperMagicsD[s]
                   : BishopMagics[s];
   return m.attacks[m.index(occupied)];
 }
@@ -403,7 +410,8 @@ inline Square lsb(Bitboard b);
 inline Bitboard rider_attacks_bb(RiderType R, Square s, Bitboard occupied) {
 
   assert(R == RIDER_BISHOP || R == RIDER_ROOK_H || R == RIDER_ROOK_V || R == RIDER_CANNON_H || R == RIDER_CANNON_V
-         || R == RIDER_HORSE || R == RIDER_ELEPHANT || R == RIDER_JANGGI_ELEPHANT || R == RIDER_CANNON_DIAG || R == RIDER_NIGHTRIDER);
+         || R == RIDER_HORSE || R == RIDER_ELEPHANT || R == RIDER_JANGGI_ELEPHANT || R == RIDER_CANNON_DIAG || R == RIDER_NIGHTRIDER
+         || R == RIDER_GRASSHOPPER_H || R == RIDER_GRASSHOPPER_V || R == RIDER_GRASSHOPPER_D);
   const Magic& m = magics[lsb(R)][s]; // re-use Bitboard lsb for riders
   return m.attacks[m.index(occupied)];
 }
index e12eb46..580e25a 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifdef PRECOMPUTED_MAGICS
 #define B(a, b) (Bitboard(a) << 64) ^ Bitboard(b)
-  // Use precomputed magics if pext is not avaible,
+  // Use precomputed magics if pext is not available,
   // since the magics generation is very slow.
   Bitboard RookMagicHInit[SQUARE_NB] = {
       B(0x120000880110000, 0x1008000000020020),
       B(0x2000010441A0044, 0x500800502020188),
       B(0xA80000000180000, 0x234402012110080),
   };
+  Bitboard GrasshopperMagicHInit[SQUARE_NB] = {
+      B(0x120000880110000, 0x1008000000020020),
+      B(0x24200C080840A052, 0x2004004000010008),
+      B(0xC030024000228800, 0x4000010400000020),
+      B(0x1A0020802008802, 0x206010208000),
+      B(0x12002000D001024, 0x80100800090138),
+      B(0x4220010000241010, 0x3098000602001500),
+      B(0x401010004801040, 0x8000280480100000),
+      B(0x820082024921836, 0x220028000),
+      B(0x100400502411400, 0x220402120240D14),
+      B(0x880202020010404, 0xA80202510000),
+      B(0x140002801000018, 0x1000346490040),
+      B(0x120000880110000, 0x1008000000020020),
+      B(0xD01004008030400, 0x104000408104420),
+      B(0x8420060100020000, 0x800280400000120),
+      B(0x4010020018010, 0x40A00001100000),
+      B(0x40006A0004000200, 0x40000000110),
+      B(0xD01004008030400, 0x104000408104420),
+      B(0x8908A20028110011, 0x800080000001A114),
+      B(0x200042000080F009, 0x20001000004000),
+      B(0x2820008820100, 0x10002400058000B9),
+      B(0x6083100420008050, 0x4040012600280080),
+      B(0x216020000000446, 0x4080204000000211),
+      B(0x340140003002089, 0x2402008000000911),
+      B(0xD01004008030400, 0x104000408104420),
+      B(0x1404040B20001000, 0x8000824010800011),
+      B(0x8C0488120024214, 0x8414880202291),
+      B(0x1010000060050000, 0x4000004050002602),
+      B(0x4022983A0060000, 0x80000040010400),
+      B(0x1404040B20001000, 0x8000824010800011),
+      B(0x6020101802002840, 0x31000003000004),
+      B(0x9000420008840, 0x4881300000000210),
+      B(0xA200808865, 0x41C0048023000128),
+      B(0x31801100400000, 0x8802DC001221240),
+      B(0x884000080200920, 0x1004002410401001),
+      B(0x2400040000884, 0x421006208040C0),
+      B(0x1404040B20001000, 0x8000824010800011),
+      B(0x24100400060009, 0x112008025042410),
+      B(0x1800040009040200, 0x180000A1004E408A),
+      B(0x24100400060009, 0x112008025042410),
+      B(0x4060402008080, 0xC240080000110000),
+      B(0x20080100920020, 0x2002248010242052),
+      B(0x10001010802050, 0x880000001C98420),
+      B(0x4000800100420022, 0x502022010A00D0),
+      B(0x4C18104500200885, 0x400880800),
+      B(0x8080810081020090, 0x8000000000000),
+      B(0x8000062812080201, 0x8004C8300800),
+      B(0xC010220920198, 0x85000A08000),
+      B(0x24100400060009, 0x112008025042410),
+      B(0x80102204040, 0x1000000900000000),
+      B(0x2080000004202804, 0x120880003461),
+      B(0x102004090A4030, 0x801020589240),
+      B(0x20001100814000A0, 0x420202000820004),
+      B(0x100800000A000120, 0x208000800010000),
+      B(0x1008205000040802, 0x80002000400040),
+      B(0x1480000098008401, 0xA0010000581010),
+      B(0x30C0008200100820, 0x102800080904834),
+      B(0x4810821884000500, 0x4400000200000212),
+      B(0x1811D00128A0180, 0x2500848803000000),
+      B(0x41618A0300040040, 0x21200200A421801),
+      B(0x80102204040, 0x1000000900000000),
+      B(0xA1808E0100108000, 0x2008000505000002),
+      B(0x8C890020410000A0, 0xA010000048000400),
+      B(0x40006002210044, 0x600008000408000),
+      B(0x1200447220090042, 0x80001000160012),
+      B(0x48410010AB000000, 0x9200600000000100),
+      B(0x2040000000240003, 0x8020080288000600),
+      B(0x9080000088848088, 0x4010210500000041),
+      B(0xA1808E0100108000, 0x2008000505000002),
+      B(0x480100400024, 0x1004800018200000),
+      B(0x808403080080200, 0x802601000000500),
+      B(0x8C890020410000A0, 0xA010000048000400),
+      B(0xA1808E0100108000, 0x2008000505000002),
+      B(0x100A40000004008, 0x2800200400200480),
+      B(0x100A40000004008, 0x2800200400200480),
+      B(0x400014006000000, 0x10006000810001F5),
+      B(0xC410062001414, 0x820080041B01044),
+      B(0x20000800310, 0x430040000201000),
+      B(0xA40010008000008, 0x4002200028000040),
+      B(0xC00102000008021C, 0x10C2000A010E024),
+      B(0x80004200104008, 0x50A00800C400020),
+      B(0x20200080012542, 0x910F0040000402C0),
+      B(0xB040100504000300, 0x24802002000040),
+      B(0x800001000014008, 0x400031004000),
+      B(0x100A40000004008, 0x2800200400200480),
+      B(0x84008002041081C0, 0x8080500200000000),
+      B(0x440090001012001, 0x4020004010),
+      B(0x100A0028088020, 0x80040E00010020),
+      B(0x2180808000810, 0xB018040A00040000),
+      B(0x40C80920304C4001, 0x42800B200800000),
+      B(0x85000425001000, 0x4810048020001100),
+      B(0x600C000801000004, 0x8015084010200020),
+      B(0x20020050000240C0, 0x100202008600800),
+      B(0x38000050001220, 0x9200010200145900),
+      B(0x1042108040005, 0x1402A0802201001),
+      B(0x824240000C20400, 0x1000000400080010),
+      B(0x84008002041081C0, 0x8080500200000000),
+      B(0x400804A1000008, 0x1024104A0200010),
+      B(0x8000402308483, 0x20006020100100),
+      B(0x80880120000080, 0x8000240100084),
+      B(0x5840020004882001, 0x1004528000A00010),
+      B(0x8001018800300002, 0x84010040804),
+      B(0x180D10004000A008, 0xA001080008020004),
+      B(0x400080B, 0x10A0000004010000),
+      B(0x8080000200000, 0x2001000082004E0),
+      B(0x40040001000C2000, 0x2024800001004008),
+      B(0x400804A1000008, 0x1024104A0200010),
+      B(0x8000402308483, 0x20006020100100),
+      B(0x400804A1000008, 0x1024104A0200010),
+      B(0x2000200000, 0x1201011000802),
+      B(0x100100000000C4, 0x208004084048201),
+      B(0x400084000044, 0x100810140300),
+      B(0x29040C0C01010, 0x300204010820080),
+      B(0x1A808000020200, 0x1000000005210040),
+      B(0x20000400150000, 0x85008020),
+      B(0x40C040008184014, 0x8002AA00024010),
+      B(0x202000081B00804, 0x10001002008),
+      B(0x40011000210060, 0x6080C40000021004),
+      B(0x2000200000, 0x1201011000802),
+      B(0x4100480203840, 0x300080100804),
+      B(0x2000200000, 0x1201011000802),
+  };
+  Bitboard GrasshopperMagicVInit[SQUARE_NB] = {
+      B(0x202000812104400, 0x24800B01C0000303),
+      B(0x340020400010D, 0x88060150C00400),
+      B(0x400802040609, 0x49010200501A0002),
+      B(0x8002680301000208, 0x628006C0C020200),
+      B(0x20400209001C0804, 0xA044000800143110),
+      B(0xC400082060010202, 0x4000480401014000),
+      B(0x22500200144040, 0x8204820084704C00),
+      B(0x8C1204009030020, 0x328400805000000),
+      B(0x84800800D0001640, 0x200080040060108),
+      B(0x804810208020040, 0x140010108020000),
+      B(0x1102010B008004, 0x300208006220020),
+      B(0x140080404A0A2428, 0x6308010100080),
+      B(0x20444002120408, 0xA080010508010001),
+      B(0x82011044000D02, 0x4112028620110809),
+      B(0x81010831000C02, 0x408802085000000),
+      B(0x81010831000C02, 0x408802085000000),
+      B(0x920008920600040, 0x8053801004000028),
+      B(0x81140283208300, 0x10040C004200420),
+      B(0x103080022201, 0xC01000081312620),
+      B(0x2200221100008, 0x1000408104000A4),
+      B(0x4402088080042008, 0x210401501040340),
+      B(0x898400202170001, 0x80040404208000),
+      B(0x20080004051012, 0x5100048200081800),
+      B(0x2320020000401018, 0x108501021040210),
+      B(0x21080410A422021, 0x83040180008800),
+      B(0x44E8100000408224, 0x20010008040400),
+      B(0x1800240002810405, 0x23004820000020),
+      B(0x80A0100400110, 0x80104020100C4028),
+      B(0x1002050001222C0, 0x5100818004024020),
+      B(0x104000200040, 0xC010A09800102000),
+      B(0x1020003A058120, 0x450900809000302),
+      B(0x40040045008B1, 0x202800400383010),
+      B(0x4640200220034, 0x8800485420304000),
+      B(0x5001042100084288, 0x110820001240080A),
+      B(0x2002C04004010120, 0xA15008020880001),
+      B(0x2800004080C4190, 0x890808280020080),
+      B(0x40C0401000104000, 0x2020880008002580),
+      B(0x40020C002400802, 0x801104010000000),
+      B(0x44842000040080, 0x2050011084000400),
+      B(0x4110040800000401, 0x2023810029008000),
+      B(0x20884000840, 0x8017102004008000),
+      B(0x10411104000480, 0x1414042000201001),
+      B(0x220040000008, 0x800306021000000),
+      B(0x41400A0008080, 0x501000298ACAD10),
+      B(0x800240012831810, 0x80120004468050E),
+      B(0x800005020801008, 0x20102400240000),
+      B(0x20C00040C114C010, 0x88080820200C00),
+      B(0x1044010100820081, 0x20080841004000),
+      B(0x8041048400022, 0x8020836040005002),
+      B(0x2001004010205, 0x8001002884042009),
+      B(0x128088400087, 0x20008002201002),
+      B(0x8084108040402000, 0x80809000A080400),
+      B(0x408081840880, 0x201002088000040),
+      B(0xA40180010280, 0x241004006000010),
+      B(0x4204100080048140, 0x2002C4F104202020),
+      B(0x100140A10204, 0x980200800840060),
+      B(0x1005140010202048, 0x1442280800202815),
+      B(0x2000082025008600, 0x1108400040600003),
+      B(0x1005050648000, 0x200020240008002),
+      B(0x202010208044000, 0x8210404060008),
+      B(0x8011040402000210, 0xC840180408016004),
+      B(0x404098801028, 0x80020A0001000400),
+      B(0x404098801028, 0x80020A0001000400),
+      B(0x80101002180140, 0x40C2080820000C0),
+      B(0x208202081260800, 0x14090E4C04000050),
+      B(0x4221201084004C2, 0x110480A011060),
+      B(0x8000008421090204, 0x1C01010800024),
+      B(0x8000008421090204, 0x1C01010800024),
+      B(0x200180C840088A0, 0x401100400820000),
+      B(0x10084043A021070, 0x202041600080200),
+      B(0x210E6202001040C, 0x10100800080B0),
+      B(0x848008021204002, 0x801004308100BAD),
+      B(0xC082C0390A000601, 0x4040080189008),
+      B(0x431200240210402D, 0x58102820000),
+      B(0x202020100A0019B0, 0x4010C0D018000000),
+      B(0x800800908402203, 0x102948C84C184),
+      B(0x26801100080845, 0x4009702022A00820),
+      B(0x8880520010401040, 0x1060084832052000),
+      B(0x100100022042081, 0x10000600008C121),
+      B(0x46020384100040, 0x800200320882021),
+      B(0xC0002010148, 0x4200800800040003),
+      B(0x2002208020090040, 0x40820210021410),
+      B(0x9000A41160002004, 0x2A09000100080043),
+      B(0x800004010008001, 0x1108002020104600),
+      B(0x800540C000A4E041, 0x18021180000401),
+      B(0x808200900A900202, 0x8364202140012005),
+      B(0x1DBA52000081010, 0x4008000023000010),
+      B(0x4100110204401481, 0x800040091020001C),
+      B(0x4100110204401481, 0x800040091020001C),
+      B(0x4101100020400482, 0x2000402302100120),
+      B(0x100408000A020212, 0xA000400111000020),
+      B(0x2000010488080104, 0x3000404410208100),
+      B(0x2684220180008DD0, 0x422040200004000A),
+      B(0x2021200C0424, 0x1010100000080200),
+      B(0x8908020020801006, 0x3010800020C2000),
+      B(0x4000030008062044, 0x244010202688000),
+      B(0x242101200408009, 0x8150040000200015),
+      B(0x42004C02180204, 0x210208014241040),
+      B(0x4E1A01C208410804, 0x8890041000012004),
+      B(0x2080200401000080, 0x8001098429008004),
+      B(0xA01400121804104, 0x280200C400000500),
+      B(0xD0080408040420, 0x1006040100224000),
+      B(0x28400205000800C9, 0x6021101401040075),
+      B(0x4000900040020104, 0x88129801100D0C),
+      B(0x8000004002180410, 0x400380200400204),
+      B(0x4002A430043008, 0x400200340100020),
+      B(0x401960004140A42, 0x100880710000464),
+      B(0x58014090102, 0xB8D30004010080),
+      B(0xA004C08000244000, 0x11280100E0000040),
+      B(0x2102008089208804, 0x110001004080040),
+      B(0x700010084E003004, 0x8080864112000D40),
+      B(0x4080881000200C20, 0x30324040880E0600),
+      B(0x2024A40401810820, 0x3000888002000000),
+      B(0x8200100400014, 0x4400340800252844),
+      B(0x24A00804288281, 0x410103002201140),
+      B(0x4080005022A08, 0x1000402200100264),
+      B(0x200080032244040, 0x200502189010001),
+      B(0x28108110404001, 0x400600120008412),
+      B(0xA00002102810020, 0xB1080240015408),
+      B(0x810080200806, 0x410440804080046),
+  };
+  Bitboard GrasshopperMagicDInit[SQUARE_NB] = {
+      B(0x811801000400, 0x312260280280202),
+      B(0x44A000402022680, 0x1020224880420005),
+      B(0x8000C80800200880, 0x2000810060080C0),
+      B(0x2010300240428040, 0x40240002C004E30),
+      B(0x1018010404010004, 0x1001010018081E0),
+      B(0x2042040010080090, 0x100000008410300),
+      B(0x400080020102000, 0x4500005300000000),
+      B(0x2D00C80420010200, 0x804003280020008),
+      B(0x8038820024420, 0x6010010080012040),
+      B(0x1202028004200088, 0x50018100004000C6),
+      B(0xA02010F0410081, 0x20013001000009A),
+      B(0x4013002041030588, 0x4802004110000004),
+      B(0x110020802000081, 0x202001800908002),
+      B(0x22010404103, 0x2020882080491200),
+      B(0x60000220400580, 0x85902800100100),
+      B(0x100080800050100, 0x200010220021088),
+      B(0x8088840404200080, 0x140011040104000),
+      B(0x4008508080082015, 0x8010100200580048),
+      B(0x4010400420201001, 0x260002080A80808),
+      B(0xC2002004A0008008, 0x8020082000110840),
+      B(0xA000A0820042400, 0x810408082100420),
+      B(0x80231808100004, 0x204002000800400),
+      B(0x8296144044004900, 0x4A1003008001840),
+      B(0x80A0020A0011008, 0x800104846080810),
+      B(0x803800801041000, 0x1030500102000404),
+      B(0x240C00900800850, 0x1804000108810000),
+      B(0x800400000088800, 0x800021801020000),
+      B(0x84800409300082, 0x1002D40680044000),
+      B(0xA110C0000200010, 0x401010001200260),
+      B(0x8200160204100004, 0x8040004004002022),
+      B(0x10001000000100C0, 0x84002811000200),
+      B(0x2000080020014001, 0x42002020000102),
+      B(0x109040044020018, 0x2020400202001000),
+      B(0x620000CD0108, 0x40040201008000),
+      B(0xA1402200A0020, 0x81400400300912),
+      B(0x20020CF100018020, 0x801A14086404000),
+      B(0x800801844001, 0x11621488425000),
+      B(0x10201004A8080, 0x100A000801000010),
+      B(0x2800411001000800, 0x80224084900020),
+      B(0x40400024028100, 0x501000400230060),
+      B(0x404808010080, 0x1201000400100004),
+      B(0x80802005200, 0x2000200008A0000),
+      B(0x20800080000022, 0x80040810002010),
+      B(0x40016004808240, 0x400114000801100),
+      B(0x8410004204240, 0x20011000604050),
+      B(0x8000C1009008268, 0x201004000209000),
+      B(0x10240C000920, 0xE000A5C14003002),
+      B(0x10184024280008, 0x90240802000000),
+      B(0x40889081081000, 0x8010050008800000),
+      B(0x100008C089000019, 0x802032014020010),
+      B(0x401C1804C00, 0x402501002002020),
+      B(0x200022000920D0, 0x8000800081300020),
+      B(0x801000400011, 0x400100044010226),
+      B(0x4A04010100100000, 0x500400080400000),
+      B(0xA000050200080000, 0x8500090001010000),
+      B(0x40400040001812, 0x4403000400100A0),
+      B(0x20C2250203020004, 0x210001C000080000),
+      B(0x21000408C6020001, 0x4200830012D1001),
+      B(0x840082016080A210, 0x2400080801081008),
+      B(0x40001020000, 0x4041240200083120),
+      B(0x2C04030010C0818, 0xA670002000818100),
+      B(0x4704A07085000510, 0x914001000040),
+      B(0x900210304100100, 0x1010004000281840),
+      B(0x8202920002002040, 0x810012000003),
+      B(0x4001400100050, 0x1144000408002000),
+      B(0x5900200020008100, 0x40200020002004),
+      B(0x301020002000480, 0x202000C0004),
+      B(0x20D000201104040, 0x34840100020010),
+      B(0x800004200080408, 0x40184200100240),
+      B(0x8430080100404020, 0x90042100244500),
+      B(0x3800100010220062, 0x50404030200218),
+      B(0x42E20008002020, 0x2000008200200300),
+      B(0xE488008280A004, 0x200001010CC80000),
+      B(0x6018010041109810, 0x800002000242041A),
+      B(0x40A8002438980, 0x8000810008208009),
+      B(0x401000480040100, 0x286800404002212),
+      B(0x821030000100009, 0x2000090200A00000),
+      B(0x20000100C0008028, 0x5000000100400082),
+      B(0x80A000048030080, 0x200000120200008),
+      B(0x6300280800204003, 0x48000105C0040100),
+      B(0x83008802420C0200, 0x2008020200080100),
+      B(0x1050C3102200042, 0x20103900010008),
+      B(0x8040902021408180, 0x12000021806200A4),
+      B(0x3008204008C10004, 0x680110100010401),
+      B(0x204321100421000, 0x400E204820494000),
+      B(0x8000044022404048, 0x4024010090024021),
+      B(0x140201424050, 0x280A000130008000),
+      B(0x900340808004002, 0x21026008000380),
+      B(0x82808000300444, 0x20002000A2001141),
+      B(0x140180100406002, 0x4004480001000004),
+      B(0x4808420800841900, 0x14008C0041000000),
+      B(0x2008600009000480, 0x9008020001400000),
+      B(0x2000100800100002, 0x2004100820210020),
+      B(0x2062010401A8100, 0x12200108420090),
+      B(0x1403188200032, 0x40048166105000),
+      B(0x410020020140041, 0x4400348102940040),
+      B(0x414040209208041, 0x4402400028B004),
+      B(0x8008010100421202, 0x401418002008800),
+      B(0x4000020010062200, 0xA02009148048000),
+      B(0x4443080082008B, 0x104014022801010),
+      B(0x42B440A0C000800, 0x9001009016111020),
+      B(0x400000214002, 0x8008080209020009),
+      B(0x480C414A001900, 0x3400100400210200),
+      B(0x1006008800604, 0x20240004030A050),
+      B(0x4C022401002A8300, 0x405008400000600),
+      B(0x3104000800A1042, 0x2004800204406200),
+      B(0xA09010280008200C, 0x4004000208C4168),
+      B(0x2800401120C20120, 0x4A00450200022030),
+      B(0x88001800304C0200, 0x204288102080000),
+      B(0x8044004201440101, 0x400820080C024022),
+      B(0xA000100C080, 0x4B40341004008081),
+      B(0x94802001300810, 0x140206008000800),
+      B(0x40002020202820, 0x280680404000040),
+      B(0xA820800004200, 0x80E1401012000491),
+      B(0x804000010020C000, 0x9403020200802000),
+      B(0x8C0001284201400, 0xC000100C01620800),
+      B(0x4010004002200414, 0x403080080200000),
+      B(0x140400A100800101, 0x10054C031080400),
+      B(0x20012C2400880082, 0x7000880020C03200),
+      B(0x204040300004, 0x840800041101002),
+  };
 #undef B
 #endif
 
index c3df461..a3ae1fd 100644 (file)
@@ -418,9 +418,14 @@ enum RiderType : int {
   RIDER_JANGGI_ELEPHANT = 1 << 7,
   RIDER_CANNON_DIAG = 1 << 8,
   RIDER_NIGHTRIDER = 1 << 9,
-  HOPPING_RIDERS = RIDER_CANNON_H | RIDER_CANNON_V | RIDER_CANNON_DIAG,
+  RIDER_GRASSHOPPER_H = 1 << 10,
+  RIDER_GRASSHOPPER_V = 1 << 11,
+  RIDER_GRASSHOPPER_D = 1 << 12,
+  HOPPING_RIDERS =  RIDER_CANNON_H | RIDER_CANNON_V | RIDER_CANNON_DIAG
+                  | RIDER_GRASSHOPPER_H | RIDER_GRASSHOPPER_V | RIDER_GRASSHOPPER_D,
   LAME_LEAPERS = RIDER_HORSE | RIDER_ELEPHANT | RIDER_JANGGI_ELEPHANT,
-  ASYMMETRICAL_RIDERS = RIDER_HORSE | RIDER_JANGGI_ELEPHANT,
+  ASYMMETRICAL_RIDERS =  RIDER_HORSE | RIDER_JANGGI_ELEPHANT
+                       | RIDER_GRASSHOPPER_H | RIDER_GRASSHOPPER_V | RIDER_GRASSHOPPER_D,
   NON_SLIDING_RIDERS = HOPPING_RIDERS | LAME_LEAPERS | RIDER_NIGHTRIDER,
 };
 
index 9ec87e3..6ea5280 100644 (file)
@@ -96,7 +96,7 @@
 # - all base moves/atoms (W, F, etc.)
 # - all directional modifiers (f, b, etc.)
 # - limited and unlimited distance sliders/riders for W/R, F/B, and N directions
-# - hoppers for W/R and F/B directions, i.e., pR and pB
+# - hoppers and grasshoppers for W/R and F/B directions, i.e., pR, pB, gR, and gB
 # - lame leapers (n) for N, A, and Z directions, i.e., nN, nA, and nZ
 
 ### Piece values
@@ -681,3 +681,9 @@ startFen = 3mm3/8/8/8/8/8/PPPPPPPP/RNBQKBNR w KQ - 0 1
 extinctionValue = loss
 extinctionPieceTypes = m
 extinctionPseudoRoyal = true
+
+[grasshopper:chess]
+customPiece1 = g:gQ
+startFen = rnbqkbnr/gggggggg/pppppppp/8/8/PPPPPPPP/GGGGGGGG/RNBQKBNR w KQkq - 0 1
+promotionPieceTypes = brqng
+doubleStep = false