1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
struct bitboard
{
enum { N = 8 } ;
typedef std::bitset<N*N> bitset ;
// empty, white king, white queen, ..., black rook, black pawn
enum piece_t { WK = 0, WQ, WB, WN, WR, WP, BK, BQ, BB, BN, BR, BP,
NTYPES = BP+1, NOTHING } ;
bitset board[ NTYPES ] ;
enum col_t { A, B, C, D, E, F, G, H } ;
static inline std::size_t offset( col_t col, int row ) // eg. E5
{ return col*N + row ; }
inline bool empty( col_t col, int row ) const // is this square empty?
{
const auto pos = offset( col, row ) ;
for( const bitset& bs : board ) if( bs[pos] ) return false ;
return true ;
}
inline piece_t piece( col_t col, int row ) const
{
const auto pos = offset( col, row ) ;
for( int i=0 ; i<NTYPES ; ++i ) if( board[i][pos] ) return piece_t(i) ;
return NOTHING ;
}
// etc
};
|