Reintroduce initialization of some bitboards
authorMarco Costalba <mcostalba@gmail.com>
Thu, 10 Mar 2011 13:39:53 +0000 (14:39 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Thu, 10 Mar 2011 18:23:39 +0000 (19:23 +0100)
With off-by-one bug in InFrontBB[] loop fixed.

Also use int instead of File to workaround a bug
in mingw 4.4.0 in first loop that cycles forever.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/bitboard.cpp
src/bitboard.h

index c4d34aeb1737b6513b527794a793da545dfe97fd..110609d294c8ce75180b15d01daf094807f450a5 100644 (file)
@@ -156,51 +156,6 @@ const int RShift[64] = {
 
 #endif // defined(IS_64BIT)
 
-static const Bitboard DarkSquaresBB  = 0xAA55AA55AA55AA55ULL;
-
-const Bitboard SquaresByColorBB[2] = { DarkSquaresBB, ~DarkSquaresBB };
-
-const Bitboard FileBB[8] = {
-  FileABB, FileBBB, FileCBB, FileDBB, FileEBB, FileFBB, FileGBB, FileHBB
-};
-
-const Bitboard NeighboringFilesBB[8] = {
-  FileBBB, FileABB|FileCBB, FileBBB|FileDBB, FileCBB|FileEBB,
-  FileDBB|FileFBB, FileEBB|FileGBB, FileFBB|FileHBB, FileGBB
-};
-
-const Bitboard ThisAndNeighboringFilesBB[8] = {
-  FileABB|FileBBB, FileABB|FileBBB|FileCBB,
-  FileBBB|FileCBB|FileDBB, FileCBB|FileDBB|FileEBB,
-  FileDBB|FileEBB|FileFBB, FileEBB|FileFBB|FileGBB,
-  FileFBB|FileGBB|FileHBB, FileGBB|FileHBB
-};
-
-const Bitboard RankBB[8] = {
-  Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB
-};
-
-const Bitboard InFrontBB[2][8] = {
-  { Rank2BB | Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
-    Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
-    Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
-    Rank5BB | Rank6BB | Rank7BB | Rank8BB,
-    Rank6BB | Rank7BB | Rank8BB,
-    Rank7BB | Rank8BB,
-    Rank8BB,
-    EmptyBoardBB
-  },
-  { EmptyBoardBB,
-    Rank1BB,
-    Rank2BB | Rank1BB,
-    Rank3BB | Rank2BB | Rank1BB,
-    Rank4BB | Rank3BB | Rank2BB | Rank1BB,
-    Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB,
-    Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB,
-    Rank7BB | Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB
-  }
-};
-
 // Global bitboards definitions with static storage duration are
 // automatically set to zero before enter main().
 Bitboard RMask[64];
@@ -214,9 +169,14 @@ Bitboard BAttacks[0x1480];
 Bitboard SetMaskBB[65];
 Bitboard ClearMaskBB[65];
 
+Bitboard SquaresByColorBB[2];
+Bitboard FileBB[8];
+Bitboard RankBB[8];
+Bitboard NeighboringFilesBB[8];
+Bitboard ThisAndNeighboringFilesBB[8];
+Bitboard InFrontBB[2][8];
 Bitboard StepAttacksBB[16][64];
 Bitboard BetweenBB[64][64];
-
 Bitboard SquaresInFrontMask[2][64];
 Bitboard PassedPawnMask[2][64];
 Bitboard AttackSpanMask[2][64];
@@ -363,6 +323,30 @@ namespace {
 
   void init_masks() {
 
+    SquaresByColorBB[DARK]  =  0xAA55AA55AA55AA55ULL;
+    SquaresByColorBB[LIGHT] = ~SquaresByColorBB[DARK];
+
+    FileBB[FILE_A] = FileABB;
+    RankBB[RANK_1] = Rank1BB;
+
+    for (int f = FILE_B; f <= FILE_H; f++)
+    {
+        FileBB[f] = FileBB[f - 1] << 1;
+        RankBB[f] = RankBB[f - 1] << 8;
+    }
+
+    for (int f = FILE_A; f <= FILE_H; f++)
+    {
+        NeighboringFilesBB[f] = (f > FILE_A ? FileBB[f - 1] : 0) | (f < FILE_H ? FileBB[f + 1] : 0);
+        ThisAndNeighboringFilesBB[f] = FileBB[f] | NeighboringFilesBB[f];
+    }
+
+    for (int rw = RANK_7, rb = RANK_2; rw >= RANK_1; rw--, rb++)
+    {
+        InFrontBB[WHITE][rw] = InFrontBB[WHITE][rw + 1] | RankBB[rw + 1];
+        InFrontBB[BLACK][rb] = InFrontBB[BLACK][rb - 1] | RankBB[rb - 1];
+    }
+
     SetMaskBB[SQ_NONE] = EmptyBoardBB;
     ClearMaskBB[SQ_NONE] = ~SetMaskBB[SQ_NONE];
 
index 2a4ab1666b7509b42e80a932d11e536fc0071a2d..2451c13928e174208335433f8e1459948b504a56 100644 (file)
@@ -43,12 +43,12 @@ const Bitboard Rank6BB = Rank1BB << (8 * 5);
 const Bitboard Rank7BB = Rank1BB << (8 * 6);
 const Bitboard Rank8BB = Rank1BB << (8 * 7);
 
-extern const Bitboard SquaresByColorBB[2];
-extern const Bitboard FileBB[8];
-extern const Bitboard NeighboringFilesBB[8];
-extern const Bitboard ThisAndNeighboringFilesBB[8];
-extern const Bitboard RankBB[8];
-extern const Bitboard InFrontBB[2][8];
+extern Bitboard SquaresByColorBB[2];
+extern Bitboard FileBB[8];
+extern Bitboard NeighboringFilesBB[8];
+extern Bitboard ThisAndNeighboringFilesBB[8];
+extern Bitboard RankBB[8];
+extern Bitboard InFrontBB[2][8];
 
 extern Bitboard SetMaskBB[65];
 extern Bitboard ClearMaskBB[65];