introduced move types

This commit is contained in:
rektdie committed 2024-03-29 14:31:32 +01:00
1 parent 06b50a4033
commit effefd1aba
2 files changed
+101 -20

No files matched your search

+76 -15
View File
@@ -16,10 +16,6 @@ static Bitboard notHfile = ~files[H];
static Bitboard notABfile = notAfile & ~files[B];
static Bitboard notHGfile = notHfile & ~files[G];
void Move::PrintMove() {
std::cout << squareCoords[moveFrom] << squareCoords[moveTo] << '\n';
}
Bitboard maskPawnAttacks(int side, int square) {
Bitboard attacks;
Bitboard attacker = Bitboard::GetSquare(square);
@@ -283,20 +279,35 @@ void GenPawnMoves(Board &board, bool color) {
Bitboard attacks = pawnAttacks[color][square] & board.colors[!color];
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()) {
int targetSquare = attacks.getLS1BIndex();
board.AddMove(Move(SQUARE(square), SQUARE(targetSquare)));
board.AddMove(Move(square, targetSquare, capture));
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);
}
}
@@ -308,15 +319,25 @@ void GenKnightMoves(Board &board, bool color) {
int square = knights.getLS1BIndex();
Bitboard attacks = knightAttacks[square] & ~board.colors[color];
Bitboard captures = attacks & board.colors[!color];
attacks &= ~captures;
while (attacks.GetBoard()) {
int targetSquare = attacks.getLS1BIndex();
board.AddMove(Move(SQUARE(square), SQUARE(targetSquare)));
board.AddMove(Move(square, targetSquare, quiet));
attacks.PopBit(targetSquare);
}
while (captures.GetBoard()) {
int targetSquare = captures.getLS1BIndex();
board.AddMove(Move(square, targetSquare, capture));
captures.PopBit(targetSquare);
}
knights.PopBit(square);
}
}
@@ -328,15 +349,25 @@ void GenRookMoves(Board &board, bool color) {
int square = rooks.getLS1BIndex();
Bitboard attacks = getRookAttack(square, board.occupied.GetBoard()) & ~board.colors[color];
Bitboard captures = attacks & board.colors[!color];
attacks &= ~captures;
while (attacks.GetBoard()) {
int targetSquare = attacks.getLS1BIndex();
board.AddMove(Move(SQUARE(square), SQUARE(targetSquare)));
board.AddMove(Move(square, targetSquare, quiet));
attacks.PopBit(targetSquare);
}
while (captures.GetBoard()) {
int targetSquare = captures.getLS1BIndex();
board.AddMove(Move(square, targetSquare, capture));
captures.PopBit(targetSquare);
}
rooks.PopBit(square);
}
}
@@ -348,15 +379,25 @@ void GenBishopMoves(Board &board, bool color) {
int square = bishops.getLS1BIndex();
Bitboard attacks = getBishopAttack(square, board.occupied.GetBoard()) & ~board.colors[color];
Bitboard captures = attacks & board.colors[!color];
attacks &= ~captures;
while (attacks.GetBoard()) {
int targetSquare = attacks.getLS1BIndex();
board.AddMove(Move(SQUARE(square), SQUARE(targetSquare)));
board.AddMove(Move(square, targetSquare, quiet));
attacks.PopBit(targetSquare);
}
while (captures.GetBoard()) {
int targetSquare = captures.getLS1BIndex();
board.AddMove(Move(square, targetSquare, capture));
captures.PopBit(targetSquare);
}
bishops.PopBit(square);
}
}
@@ -368,15 +409,25 @@ void GenQueenMoves(Board &board, bool color) {
int square = queens.getLS1BIndex();
Bitboard attacks = getQueenAttack(square, board.occupied.GetBoard()) & ~board.colors[color];
Bitboard captures = attacks & board.colors[!color];
attacks &= ~captures;
while (attacks.GetBoard()) {
int targetSquare = attacks.getLS1BIndex();
board.AddMove(Move(SQUARE(square), SQUARE(targetSquare)));
board.AddMove(Move(square, targetSquare, quiet));
attacks.PopBit(targetSquare);
}
while (captures.GetBoard()) {
int targetSquare = captures.getLS1BIndex();
board.AddMove(Move(square, targetSquare, capture));
captures.PopBit(targetSquare);
}
queens.PopBit(square);
}
}
@@ -387,14 +438,24 @@ void GenKingMoves(Board &board, bool color) {
int square = king.getLS1BIndex();
Bitboard attacks = kingAttacks[square] & ~board.colors[color];
Bitboard captures = attacks & board.colors[!color];
attacks &= ~captures;
while (attacks.GetBoard()) {
int targetSquare = attacks.getLS1BIndex();
board.AddMove(Move(SQUARE(square), SQUARE(targetSquare)));
board.AddMove(Move(square, targetSquare, quiet));
attacks.PopBit(targetSquare);
}
while (captures.GetBoard()) {
int targetSquare = captures.getLS1BIndex();
board.AddMove(Move(square, targetSquare, capture));
captures.PopBit(targetSquare);
}
}
void GenerateMoves(Board &board) {