add move.c from pre-bitboard version
This commit is contained in:
@@ -48,7 +48,6 @@ uchar bb_rank_attacks[64 * 8];
|
||||
* to save one operation in hyperbola_moves().
|
||||
* TODO ? replace rank attack with this idea, mapping rank to diagonal ?
|
||||
* See http://timcooijmans.blogspot.com/2014/04/
|
||||
*
|
||||
*/
|
||||
void hyperbola_init()
|
||||
{
|
||||
@@ -56,7 +55,8 @@ void hyperbola_init()
|
||||
*/
|
||||
for (int occ = 0; occ < 64; ++occ) {
|
||||
for (int file = 0; file < 8; ++file) {
|
||||
uchar attacks = 0;
|
||||
int attacks = 0;
|
||||
//int o = mask << 1; /* skip right square */
|
||||
|
||||
/* set f left attacks */
|
||||
for (int slide = file - 1; slide >= 0; --slide) {
|
||||
@@ -69,10 +69,18 @@ void hyperbola_init()
|
||||
for (int slide = file + 1; slide < 8; ++slide) {
|
||||
int b = bb_sq[slide];
|
||||
attacks |= b;
|
||||
if ((occ << 1) & b)
|
||||
if ((occ << 1) & b) /* piece on b, we stop */
|
||||
//if ((o & b) == b)
|
||||
break;
|
||||
}
|
||||
bb_rank_attacks[occ * 8 + file] = attacks;
|
||||
bb_rank_attacks[(occ << 3) + file] = attacks;
|
||||
|
||||
//if (((occ << 3) + file) == 171) {
|
||||
//char str[64], str2[64];
|
||||
//printf("mask=%x=%s file=%d att=%x=%s\n",
|
||||
// occ, bitboard_rank_sprint(str, occ), file,
|
||||
// attacks, bitboard_rank_sprint(str2, attacks));
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,11 +96,16 @@ void hyperbola_init()
|
||||
*/
|
||||
static bitboard_t hyperbola_rank_moves(bitboard_t occ, square_t sq)
|
||||
{
|
||||
uint32_t rank = sq & SQ_FILEMASK;
|
||||
uint32_t file = sq & SQ_RANKMASK;
|
||||
uint64_t o = (occ >> rank) & 0x7e; /* 01111110 clear bits 0 & 7 */
|
||||
|
||||
return ((bitboard_t)bb_rank_attacks[o * 4 + file]) << rank;
|
||||
u32 rank = sq & SQ_RANKMASK;
|
||||
u32 file = sq & SQ_FILEMASK;
|
||||
u64 o = (occ >> rank) & 0176; /* 01111110 clear bits 0 & 7 */
|
||||
//char zob[128], zob2[128];
|
||||
//printf("rank_moves: occ=%lx=%s file=%d o=%lx=%s index=%ld=%ld attack=%lx=%s\n", occ,
|
||||
// bitboard_rank_sprint(zob, occ), file, o,
|
||||
// bitboard_rank_sprint(zob, o), (o << 2) + file, (o * 4) + file,
|
||||
// (bitboard_t)bb_rank_attacks[(o << 2) + file] << rank,
|
||||
// bitboard_rank_sprint(zob2, (bitboard_t)bb_rank_attacks[(o << 2) + file] << rank));
|
||||
return ((bitboard_t)bb_rank_attacks[(o << 2) + file]) << rank;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,30 +132,30 @@ static bitboard_t hyperbola_moves(const bitboard_t pieces, const square_t sq,
|
||||
|
||||
static bitboard_t hyperbola_file_moves(bitboard_t occ, square_t sq)
|
||||
{
|
||||
return hyperbola_moves(occ, bb_file[sq], sq);
|
||||
return hyperbola_moves(occ, sq, bb_file[sq]);
|
||||
}
|
||||
|
||||
static bitboard_t hyperbola_diag_moves(bitboard_t occ, square_t sq)
|
||||
{
|
||||
return hyperbola_moves(occ, bb_diag[sq], sq);
|
||||
return hyperbola_moves(occ, sq, bb_diag[sq]);
|
||||
}
|
||||
|
||||
static bitboard_t hyperbola_anti_moves(bitboard_t occ, square_t sq)
|
||||
{
|
||||
return hyperbola_moves(occ, bb_anti[sq], sq);
|
||||
return hyperbola_moves(occ, sq, bb_anti[sq]);
|
||||
}
|
||||
|
||||
bitboard_t hyperbola_bishop_moves(bitboard_t occ, square_t sq)
|
||||
{
|
||||
return hyperbola_diag_moves(occ, sq) + hyperbola_anti_moves(occ, sq);
|
||||
return hyperbola_diag_moves(occ, sq) | hyperbola_anti_moves(occ, sq);
|
||||
}
|
||||
|
||||
bitboard_t hyperbola_rook_moves(bitboard_t occ, square_t sq)
|
||||
{
|
||||
return hyperbola_file_moves(occ, sq) + hyperbola_rank_moves(occ, sq);
|
||||
return hyperbola_file_moves(occ, sq) | hyperbola_rank_moves(occ, sq);
|
||||
}
|
||||
|
||||
bitboard_t hyperbola_queen_moves(bitboard_t occ, square_t sq)
|
||||
{
|
||||
return hyperbola_bishop_moves(occ, sq) + hyperbola_rook_moves(occ, sq);
|
||||
return hyperbola_bishop_moves(occ, sq) | hyperbola_rook_moves(occ, sq);
|
||||
}
|
||||
|
Reference in New Issue
Block a user