introduced move types
This commit is contained in:
1 parent
06b50a4033
commit
effefd1aba
2 files changed
+101
-20
No files matched your search
+25
-5
@@ -1,15 +1,35 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "bitboards.h"
|
#include "bitboards.h"
|
||||||
|
|
||||||
|
enum MOVE_FLAGS {
|
||||||
|
quiet, doublePawnPush,
|
||||||
|
kingCastle, QueenCastle,
|
||||||
|
capture, epCapture,
|
||||||
|
knightPromotion, bishopPromotion, rookPromotion, queenPromotion,
|
||||||
|
knightPromoCapture, bishopPromoCapture, rookPromoCapture, queenPromoCapture
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr std::array<const char*, 14> moveTypes {
|
||||||
|
"quiet", "doublePawnPush",
|
||||||
|
"kingCastle", "QueenCastle",
|
||||||
|
"capture", "epCapture",
|
||||||
|
"knightPromotion", "bishopPromotion", "rookPromotion", "queenPromotion",
|
||||||
|
"knightPromoCapture", "bishopPromoCapture", "rookPromoCapture", "queenPromoCapture"
|
||||||
|
};
|
||||||
|
|
||||||
struct Move {
|
struct Move {
|
||||||
public:
|
public:
|
||||||
SQUARE moveFrom;
|
int moveFrom;
|
||||||
SQUARE moveTo;
|
int moveTo;
|
||||||
|
uint16_t moveFlags;
|
||||||
|
|
||||||
Move(){}
|
Move(){}
|
||||||
|
|
||||||
Move(const SQUARE from, const SQUARE to)
|
Move(const int from, const int to, const uint16_t flags)
|
||||||
: moveFrom(from), moveTo(to) {}
|
: moveFrom(from), moveTo(to), moveFlags(flags) {}
|
||||||
|
|
||||||
void PrintMove();
|
void PrintMove() {
|
||||||
|
std::cout << squareCoords[moveFrom] << squareCoords[moveTo];
|
||||||
|
std::cout << '(' << moveTypes[moveFlags] << ")\n";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
+76
-15
@@ -16,10 +16,6 @@ static Bitboard notHfile = ~files[H];
|
|||||||
static Bitboard notABfile = notAfile & ~files[B];
|
static Bitboard notABfile = notAfile & ~files[B];
|
||||||
static Bitboard notHGfile = notHfile & ~files[G];
|
static Bitboard notHGfile = notHfile & ~files[G];
|
||||||
|
|
||||||
void Move::PrintMove() {
|
|
||||||
std::cout << squareCoords[moveFrom] << squareCoords[moveTo] << '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
Bitboard maskPawnAttacks(int side, int square) {
|
Bitboard maskPawnAttacks(int side, int square) {
|
||||||
Bitboard attacks;
|
Bitboard attacks;
|
||||||
Bitboard attacker = Bitboard::GetSquare(square);
|
Bitboard attacker = Bitboard::GetSquare(square);
|
||||||
@@ -283,20 +279,35 @@ void GenPawnMoves(Board &board, bool color) {
|
|||||||
Bitboard attacks = pawnAttacks[color][square] & board.colors[!color];
|
Bitboard attacks = pawnAttacks[color][square] & board.colors[!color];
|
||||||
|
|
||||||
Bitboard firstAhead = Bitboard::GetSquare(square + direction) & ~board.occupied;
|
Bitboard firstAhead = Bitboard::GetSquare(square + direction) & ~board.occupied;
|
||||||
|
Bitboard secondAhead = Bitboard::GetSquare(square + 2 * direction) & ~board.occupied;
|
||||||
|
|
||||||
if (firstAhead.GetBoard()) {
|
|
||||||
attacks |= firstAhead;
|
|
||||||
attacks |= Bitboard::GetSquare(square + 2 * direction) & ~board.occupied;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (attacks.GetBoard()) {
|
while (attacks.GetBoard()) {
|
||||||
int targetSquare = attacks.getLS1BIndex();
|
int targetSquare = attacks.getLS1BIndex();
|
||||||
|
|
||||||
board.AddMove(Move(SQUARE(square), SQUARE(targetSquare)));
|
board.AddMove(Move(square, targetSquare, capture));
|
||||||
|
|
||||||
attacks.PopBit(targetSquare);
|
attacks.PopBit(targetSquare);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (firstAhead.GetBoard()) {
|
||||||
|
board.AddMove(Move(square, firstAhead.getLS1BIndex(), quiet));
|
||||||
|
|
||||||
|
if (color == White) {
|
||||||
|
if (Bitboard::GetSquare(firstAhead.getLS1BIndex() & RANKS::r_2).GetBoard()) {
|
||||||
|
if ((secondAhead).GetBoard()) {
|
||||||
|
board.AddMove(Move(square, secondAhead.getLS1BIndex(), doublePawnPush));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (Bitboard::GetSquare(firstAhead.getLS1BIndex() & RANKS::r_7).GetBoard()) {
|
||||||
|
if ((secondAhead).GetBoard()) {
|
||||||
|
board.AddMove(Move(square, secondAhead.getLS1BIndex(), doublePawnPush));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pawns.PopBit(square);
|
pawns.PopBit(square);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -308,15 +319,25 @@ void GenKnightMoves(Board &board, bool color) {
|
|||||||
int square = knights.getLS1BIndex();
|
int square = knights.getLS1BIndex();
|
||||||
|
|
||||||
Bitboard attacks = knightAttacks[square] & ~board.colors[color];
|
Bitboard attacks = knightAttacks[square] & ~board.colors[color];
|
||||||
|
Bitboard captures = attacks & board.colors[!color];
|
||||||
|
attacks &= ~captures;
|
||||||
|
|
||||||
while (attacks.GetBoard()) {
|
while (attacks.GetBoard()) {
|
||||||
int targetSquare = attacks.getLS1BIndex();
|
int targetSquare = attacks.getLS1BIndex();
|
||||||
|
|
||||||
board.AddMove(Move(SQUARE(square), SQUARE(targetSquare)));
|
board.AddMove(Move(square, targetSquare, quiet));
|
||||||
|
|
||||||
attacks.PopBit(targetSquare);
|
attacks.PopBit(targetSquare);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (captures.GetBoard()) {
|
||||||
|
int targetSquare = captures.getLS1BIndex();
|
||||||
|
|
||||||
|
board.AddMove(Move(square, targetSquare, capture));
|
||||||
|
|
||||||
|
captures.PopBit(targetSquare);
|
||||||
|
}
|
||||||
|
|
||||||
knights.PopBit(square);
|
knights.PopBit(square);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -328,15 +349,25 @@ void GenRookMoves(Board &board, bool color) {
|
|||||||
int square = rooks.getLS1BIndex();
|
int square = rooks.getLS1BIndex();
|
||||||
|
|
||||||
Bitboard attacks = getRookAttack(square, board.occupied.GetBoard()) & ~board.colors[color];
|
Bitboard attacks = getRookAttack(square, board.occupied.GetBoard()) & ~board.colors[color];
|
||||||
|
Bitboard captures = attacks & board.colors[!color];
|
||||||
|
attacks &= ~captures;
|
||||||
|
|
||||||
while (attacks.GetBoard()) {
|
while (attacks.GetBoard()) {
|
||||||
int targetSquare = attacks.getLS1BIndex();
|
int targetSquare = attacks.getLS1BIndex();
|
||||||
|
|
||||||
board.AddMove(Move(SQUARE(square), SQUARE(targetSquare)));
|
board.AddMove(Move(square, targetSquare, quiet));
|
||||||
|
|
||||||
attacks.PopBit(targetSquare);
|
attacks.PopBit(targetSquare);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (captures.GetBoard()) {
|
||||||
|
int targetSquare = captures.getLS1BIndex();
|
||||||
|
|
||||||
|
board.AddMove(Move(square, targetSquare, capture));
|
||||||
|
|
||||||
|
captures.PopBit(targetSquare);
|
||||||
|
}
|
||||||
|
|
||||||
rooks.PopBit(square);
|
rooks.PopBit(square);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -348,15 +379,25 @@ void GenBishopMoves(Board &board, bool color) {
|
|||||||
int square = bishops.getLS1BIndex();
|
int square = bishops.getLS1BIndex();
|
||||||
|
|
||||||
Bitboard attacks = getBishopAttack(square, board.occupied.GetBoard()) & ~board.colors[color];
|
Bitboard attacks = getBishopAttack(square, board.occupied.GetBoard()) & ~board.colors[color];
|
||||||
|
Bitboard captures = attacks & board.colors[!color];
|
||||||
|
attacks &= ~captures;
|
||||||
|
|
||||||
while (attacks.GetBoard()) {
|
while (attacks.GetBoard()) {
|
||||||
int targetSquare = attacks.getLS1BIndex();
|
int targetSquare = attacks.getLS1BIndex();
|
||||||
|
|
||||||
board.AddMove(Move(SQUARE(square), SQUARE(targetSquare)));
|
board.AddMove(Move(square, targetSquare, quiet));
|
||||||
|
|
||||||
attacks.PopBit(targetSquare);
|
attacks.PopBit(targetSquare);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (captures.GetBoard()) {
|
||||||
|
int targetSquare = captures.getLS1BIndex();
|
||||||
|
|
||||||
|
board.AddMove(Move(square, targetSquare, capture));
|
||||||
|
|
||||||
|
captures.PopBit(targetSquare);
|
||||||
|
}
|
||||||
|
|
||||||
bishops.PopBit(square);
|
bishops.PopBit(square);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -368,15 +409,25 @@ void GenQueenMoves(Board &board, bool color) {
|
|||||||
int square = queens.getLS1BIndex();
|
int square = queens.getLS1BIndex();
|
||||||
|
|
||||||
Bitboard attacks = getQueenAttack(square, board.occupied.GetBoard()) & ~board.colors[color];
|
Bitboard attacks = getQueenAttack(square, board.occupied.GetBoard()) & ~board.colors[color];
|
||||||
|
Bitboard captures = attacks & board.colors[!color];
|
||||||
|
attacks &= ~captures;
|
||||||
|
|
||||||
while (attacks.GetBoard()) {
|
while (attacks.GetBoard()) {
|
||||||
int targetSquare = attacks.getLS1BIndex();
|
int targetSquare = attacks.getLS1BIndex();
|
||||||
|
|
||||||
board.AddMove(Move(SQUARE(square), SQUARE(targetSquare)));
|
board.AddMove(Move(square, targetSquare, quiet));
|
||||||
|
|
||||||
attacks.PopBit(targetSquare);
|
attacks.PopBit(targetSquare);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (captures.GetBoard()) {
|
||||||
|
int targetSquare = captures.getLS1BIndex();
|
||||||
|
|
||||||
|
board.AddMove(Move(square, targetSquare, capture));
|
||||||
|
|
||||||
|
captures.PopBit(targetSquare);
|
||||||
|
}
|
||||||
|
|
||||||
queens.PopBit(square);
|
queens.PopBit(square);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -387,14 +438,24 @@ void GenKingMoves(Board &board, bool color) {
|
|||||||
int square = king.getLS1BIndex();
|
int square = king.getLS1BIndex();
|
||||||
|
|
||||||
Bitboard attacks = kingAttacks[square] & ~board.colors[color];
|
Bitboard attacks = kingAttacks[square] & ~board.colors[color];
|
||||||
|
Bitboard captures = attacks & board.colors[!color];
|
||||||
|
attacks &= ~captures;
|
||||||
|
|
||||||
while (attacks.GetBoard()) {
|
while (attacks.GetBoard()) {
|
||||||
int targetSquare = attacks.getLS1BIndex();
|
int targetSquare = attacks.getLS1BIndex();
|
||||||
|
|
||||||
board.AddMove(Move(SQUARE(square), SQUARE(targetSquare)));
|
board.AddMove(Move(square, targetSquare, quiet));
|
||||||
|
|
||||||
attacks.PopBit(targetSquare);
|
attacks.PopBit(targetSquare);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (captures.GetBoard()) {
|
||||||
|
int targetSquare = captures.getLS1BIndex();
|
||||||
|
|
||||||
|
board.AddMove(Move(square, targetSquare, capture));
|
||||||
|
|
||||||
|
captures.PopBit(targetSquare);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenerateMoves(Board &board) {
|
void GenerateMoves(Board &board) {
|
||||||
|
|||||||
Reference in new issue
Block a user