Revision: 1616
Author: protonspring
Date: Mon Aug 2 15:27:38 2010
Log: a few bit manipulation changes + a few optimizations.
http://code.google.com/p/gray-matter/source/detail?r=1616
Modified:
/trunk/inc/board_base.h
/trunk/src/board_base.cpp
=======================================
--- /trunk/inc/board_base.h Mon Aug 2 14:39:20 2010
+++ /trunk/inc/board_base.h Mon Aug 2 15:27:38 2010
@@ -39,19 +39,18 @@
class board_base
{
//precomputed single bit masks
- static bitboard_t singleBitMasks[8][8];
+ static bitboard_t BIT_MSK[8][8];
public:
- inline static int BIT_IDX(int x, int y) {return ((y) << 3 |
(x));}
- inline static bitboard_t BIT_MSK(int x, int y) {return
singleBitMasks[x][y];}
- inline static bool BIT_GET(bitboard_t b, int x, int y) {return
((b) >> BIT_IDX(x, y) & 1);}
- inline static void BIT_CLR(bitboard_t& b, unsigned x, unsigned y)
{(b) &= ~BIT_MSK(x, y);}
- inline static void BIT_SET(bitboard_t& b, int x, int y) {(b) |=
BIT_MSK(x, y);}
- inline static bitboard_t BIT_MOV(bitboard_t& b, int x1, int y1, int x2,
int y2) {return ((b) ^= BIT_MSK(x1, y1) | BIT_MSK(x2, y2));}
+ inline static int BIT_IDX(int x, int y) {return ((y << 3) | x);}
+ inline static bool BIT_GET(bitboard_t b, int x, int y) {return
((b) >> BIT_IDX(x,y) & 1);}
+ inline static void BIT_CLR(bitboard_t& b, unsigned x, unsigned y)
{(b) &= ~BIT_MSK[x][y];}
+ inline static void BIT_SET(bitboard_t& b, int x, int y) {(b) |=
BIT_MSK[x][y];}
+ inline static bitboard_t BIT_MOV(bitboard_t& b, int x1, int y1, int x2,
int y2) {return ((b) ^= BIT_MSK[x1][y1] | BIT_MSK[x2][y2]);}
inline static int ROW_NUM(int x,int y,int a){return ((a) ==
ZERO ? (y) : (x));}
inline static int ROW_LOC(int x,int y,int a){return ((a) ==
ZERO ? (x) : 7 - (y));}
- inline static int ROW_IDX(int n){return (BIT_IDX(0, n));}
+ inline static int ROW_IDX(int n){return (BIT_IDX(0,n));}
inline static bitboard_t ROW_MSK(int n){return (0xFFULL << ROW_IDX(n));}
inline static bitrow_t ROW_GET(bitboard_t b, int n){return
((bitrow_t)((b) >> ROW_IDX(n) & 0xFF));}
inline static bitboard_t ROW_CLR(bitboard_t& b, int n){return ((b) &=
~ROW_MSK(n));}
@@ -59,14 +58,14 @@
// These macros manipulate columns in 0° rotated BitBoards and rows in
90°
// rotated BitBoards.
- inline static int COL_IDX(int n){return (BIT_IDX(n, 0));}
+ inline static int COL_IDX(int n){return (BIT_IDX(n,0));}
inline static bitboard_t COL_MSK(int n){return (0x0101010101010101ULL
<< COL_IDX(n));}
inline static bitboard_t COL_CLR(bitboard_t& b, int n){return ((b) &=
~COL_MSK(n));}
// These macros manipulate adjacent bits in 45° rotated BitBoards, which
// correspond to diagonals in 0° and 90° rotated BitBoards.
inline static int DIAG_NUM(int x, int y, int a){return ((a) ==
L45 ? (x) + (y) : 7 - (x) + (y));}
- inline static int DIAG_LOC(int x, int y, int a){return
(BIT_IDX(coord[MAP][a][x][y][X], coord[MAP][a][x][y][Y]) -
diag_index[DIAG_NUM(x, y, a)]);}
+ inline static int DIAG_LOC(int x, int y, int a){return
(BIT_IDX(coord[MAP][a][x][y][X],coord[MAP][a][x][y][Y]) -
diag_index[DIAG_NUM(x, y, a)]);}
inline static int DIAG_LEN(int n){return (8 - abs(7 - (n)));}
inline static int DIAG_IDX(int n){return (diag_index[n]);}
inline static bitboard_t DIAG_MSK(int n){return ((bitboard_t)
diag_mask[n] << diag_index[n]);}
=======================================
--- /trunk/src/board_base.cpp Mon Aug 2 14:39:20 2010
+++ /trunk/src/board_base.cpp Mon Aug 2 15:27:38 2010
@@ -160,7 +160,7 @@
bitboard_t board_base::key_en_passant[8];
bitboard_t board_base::key_on_move;
-uint64_t board_base::singleBitMasks[8][8];
+uint64_t board_base::BIT_MSK[8][8];
/*----------------------------------------------------------------------------*\
|
board_base() |
@@ -171,10 +171,12 @@
/// Constructor. Important! Seed the random number generator, issue
/// <code>srand(time(NULL));</code> before instantiating this class!
- //compute single bit masks
+ //compute some useful arrays
for (int i=0;i<8;++i)
for (int j=0;j<8;++j)
- singleBitMasks[j][i] = 1ULL << (i*8+j);
+ {
+ BIT_MSK[j][i] = 1ULL << (i*8+j);
+ }
if (!precomputed_board_base)
{
@@ -727,7 +729,7 @@
// If we're moving a piece to one of our opponent's rooks' initial
// positions, then make sure that our opponent is no longer marked
able to
// castle on that rook's side.
- if ((m.x2 == 0 || m.x2 == 7) && (m.y2 == (OFF_MOVE ? 7 : 0)) &&
state.castle[OFF_MOVE][m.x2 == 7] == CAN_CASTLE)
+ if ((m.x2 == 0 || m.x2 == 7) && (m.y2 == (OFF_MOVE ? 7 : 0)))// &&
state.castle[OFF_MOVE][m.x2 == 7] == CAN_CASTLE)
{
state.castle[OFF_MOVE][m.x2 == 7] = CANT_CASTLE;
hash ^= key_castle[OFF_MOVE][m.x1 == 7][CANT_CASTLE];