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 "board.h"
|
||||||
|
#include "movegen.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
void Board::Init() {
|
void Board::Init() {
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include "bitboards.h"
|
#include "bitboards.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "movegen.h"
|
#include "move.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class Board {
|
class Board {
|
||||||
|
|||||||
+3
-1
@@ -8,7 +8,9 @@ int main() {
|
|||||||
initSliderAttacks();
|
initSliderAttacks();
|
||||||
|
|
||||||
Board board;
|
Board board;
|
||||||
board.PrintBoard();
|
GenerateMoves(board);
|
||||||
|
|
||||||
|
board.ListMoves();
|
||||||
|
|
||||||
return 0;
|
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]);
|
rookOccupancy >>= (64 - rookRelevantBits[square]);
|
||||||
|
|
||||||
return rookAttacks[square][rookOccupancy] | bishopAttacks[square][bishopOccupancy];
|
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
|
#pragma once
|
||||||
#include "bitboards.h"
|
#include "bitboards.h"
|
||||||
|
#include "move.h"
|
||||||
struct Move {
|
#include "board.h"
|
||||||
public:
|
|
||||||
SQUARE moveFrom;
|
|
||||||
SQUARE moveTo;
|
|
||||||
|
|
||||||
Move(){}
|
|
||||||
|
|
||||||
Move(const SQUARE from, const SQUARE to)
|
|
||||||
: moveFrom(from), moveTo(to) {}
|
|
||||||
|
|
||||||
void PrintMove();
|
|
||||||
};
|
|
||||||
|
|
||||||
// bishop relevant occupancy bit count
|
// bishop relevant occupancy bit count
|
||||||
constexpr int bishopRelevantBits[64] = {
|
constexpr int bishopRelevantBits[64] = {
|
||||||
@@ -213,4 +202,6 @@ void initSliderAttacks();
|
|||||||
|
|
||||||
Bitboard getBishopAttack(int square, U64 occupancy);
|
Bitboard getBishopAttack(int square, U64 occupancy);
|
||||||
Bitboard getRookAttack(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