Это новый код, который использует PEXT для рассчитать схему атаки:
Код: Выделить всё
uint64_t Move_lookup::get_rook_moves(int index, uint64_t all_pieces) {
int index2 = _pext_u64(all_pieces, rook_masks[index]);
return rook_moves[index][index2];
}
Код: Выделить всё
std::vector rook_moves;Код: Выделить всё
uint64_t Board::get_rook_moves(uint64_t* b, pieceColour colour, int n) {
// We must perform the operation on the set the function was called with
uint64_t rooks = *b;
isolate_piece(&rooks, n); // This gets rid of all the 1's we are not interested in in rooks
// Get all enemy pieces
uint64_t enemy_pieces = all_pieces(invert_colour(colour));
// Combined pieces for obstacle detection
uint64_t black_white_pieces = all_pieces(colour) | enemy_pieces;
uint64_t attacks = 0ULL;
// We need to look in all four straight directions (N,E,S,W) until we hit the edge of the board or another piece
// North
uint64_t move = rooks;
while (move & NOT_RANK_8) { // Continue while not on the last rank
move = 1; // Move one file right
if (move & black_white_pieces) { // Stop if a piece is encountered
if (move & enemy_pieces) attacks |= move; // If enemy piece, include in attacks
break;
}
attacks |= move; // Add square to attacks
}
// South
move = rooks;
while (move & NOT_RANK_1) { // Continue while not on the first rank
move >>= 8; // Move one rank down
if (move & black_white_pieces) { // Stop if a piece is encountered
if (move & enemy_pieces) attacks |= move; // If enemy piece, include in attacks
break;
}
attacks |= move; // Add square to attacks
}
// West
move = rooks;
while (move & NOT_A_FILE) { // Continue while not on the A file
move
Подробнее здесь: [url]https://stackoverflow.com/questions/79151644/how-can-i-make-lookups-in-c-as-fast-as-possible[/url]
Мобильная версия