GenPawnMoves function
This commit is contained in:
1 parent
b58c6bea77
commit
2aebd781fb
6 files changed
+53
-16
No files matched your search
@@ -1,4 +1,5 @@
|
||||
#include "board.h"
|
||||
#include "movegen.h"
|
||||
#include <iostream>
|
||||
|
||||
void Board::Init() {
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
#include <array>
|
||||
#include "bitboards.h"
|
||||
#include "types.h"
|
||||
#include "movegen.h"
|
||||
#include "move.h"
|
||||
#include <vector>
|
||||
|
||||
class Board {
|
||||
|
||||
+3
-1
@@ -8,7 +8,9 @@ int main() {
|
||||
initSliderAttacks();
|
||||
|
||||
Board board;
|
||||
board.PrintBoard();
|
||||
GenerateMoves(board);
|
||||
|
||||
board.ListMoves();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "bitboards.h"
|
||||
|
||||
struct Move {
|
||||
public:
|
||||
SQUARE moveFrom;
|
||||
SQUARE moveTo;
|
||||
|
||||
Move(){}
|
||||
|
||||
Move(const SQUARE from, const SQUARE to)
|
||||
: moveFrom(from), moveTo(to) {}
|
||||
|
||||
void PrintMove();
|
||||
};
|
||||
@@ -271,4 +271,32 @@ Bitboard getQueenAttack(int square, U64 occupancy) {
|
||||
rookOccupancy >>= (64 - rookRelevantBits[square]);
|
||||
|
||||
return rookAttacks[square][rookOccupancy] | bishopAttacks[square][bishopOccupancy];
|
||||
}
|
||||
|
||||
void GenPawnMoves(Board &board, bool color) {
|
||||
Bitboard pawns = board.colors[color] & board.pieces[Pawn];
|
||||
|
||||
while (pawns.GetBoard()) {
|
||||
int square = pawns.getLS1BIndex();
|
||||
int direction = color ? south : north;
|
||||
|
||||
Bitboard attacks = pawnAttacks[color][square] & board.colors[!color];
|
||||
attacks |= (Bitboard::GetSquare(square + direction)
|
||||
| Bitboard::GetSquare(square + 2 * direction)) & ~(board.occupied);
|
||||
|
||||
while (attacks.GetBoard()) {
|
||||
int targetSquare = attacks.getLS1BIndex();
|
||||
|
||||
board.AddMove(Move(SQUARE(square), SQUARE(targetSquare)));
|
||||
|
||||
attacks.PopBit(targetSquare);
|
||||
}
|
||||
|
||||
pawns.PopBit(square);
|
||||
}
|
||||
}
|
||||
|
||||
void GenerateMoves(Board &board) {
|
||||
GenPawnMoves(board, White);
|
||||
GenPawnMoves(board, Black);
|
||||
}
|
||||
+5
-14
@@ -1,18 +1,7 @@
|
||||
#pragma once
|
||||
#include "bitboards.h"
|
||||
|
||||
struct Move {
|
||||
public:
|
||||
SQUARE moveFrom;
|
||||
SQUARE moveTo;
|
||||
|
||||
Move(){}
|
||||
|
||||
Move(const SQUARE from, const SQUARE to)
|
||||
: moveFrom(from), moveTo(to) {}
|
||||
|
||||
void PrintMove();
|
||||
};
|
||||
#include "move.h"
|
||||
#include "board.h"
|
||||
|
||||
// bishop relevant occupancy bit count
|
||||
constexpr int bishopRelevantBits[64] = {
|
||||
@@ -213,4 +202,6 @@ void initSliderAttacks();
|
||||
|
||||
Bitboard getBishopAttack(int square, U64 occupancy);
|
||||
Bitboard getRookAttack(int square, U64 occupancy);
|
||||
Bitboard getQueenAttack(int square, U64 occupancy);
|
||||
Bitboard getQueenAttack(int square, U64 occupancy);
|
||||
|
||||
void GenerateMoves(Board &board);
|
||||
Reference in new issue
Block a user