added promotion moves(with captures as well)
This commit is contained in:
1 parent
6b5127424e
commit
025ae1eceb
3 files changed
+71
-19
No files matched your search
+35
-3
@@ -282,6 +282,20 @@ bool Board::InCheck(bool side) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Board::Promote(int square, int pieceType, int color, bool isCapture) {
|
||||
if (isCapture) {
|
||||
int targetType = GetPieceType(square);
|
||||
std::cout << targetType << '\n';
|
||||
|
||||
pieces[targetType].PopBit(square);
|
||||
colors[!color].PopBit(square);
|
||||
}
|
||||
|
||||
occupied.SetBit(square);
|
||||
pieces[pieceType].SetBit(square);
|
||||
colors[color].SetBit(square);
|
||||
}
|
||||
|
||||
void Board::DoMove(Move move) {
|
||||
enPassantTarget = a1; // resetting (a1 is impossible)
|
||||
uint16_t moveType = move.moveFlags;
|
||||
@@ -292,13 +306,15 @@ void Board::DoMove(Move move) {
|
||||
|
||||
int direction = attackerColor ? south : north;
|
||||
|
||||
|
||||
pieces[attackerType].PopBit(move.moveFrom);
|
||||
colors[attackerColor].PopBit(move.moveFrom);
|
||||
occupied.PopBit(move.moveFrom);
|
||||
|
||||
pieces[attackerType].SetBit(move.moveTo);
|
||||
colors[attackerColor].SetBit(move.moveTo);
|
||||
if (moveType < knightPromotion) {
|
||||
pieces[attackerType].SetBit(move.moveTo);
|
||||
colors[attackerColor].SetBit(move.moveTo);
|
||||
}
|
||||
|
||||
if (moveType == quiet) {
|
||||
occupied.SetBit(move.moveTo);
|
||||
} else if (moveType == doublePawnPush) {
|
||||
@@ -332,6 +348,22 @@ void Board::DoMove(Move move) {
|
||||
pieces[Rook].SetBit(rookSquare - 2);
|
||||
colors[attackerColor].SetBit(rookSquare - 2);
|
||||
occupied.SetBit(rookSquare);
|
||||
} else if (moveType == knightPromotion) {
|
||||
Promote(move.moveTo, Knight, attackerColor, false);
|
||||
} else if (moveType == bishopPromotion) {
|
||||
Promote(move.moveTo, Bishop, attackerColor, false);
|
||||
} else if (moveType == rookPromotion) {
|
||||
Promote(move.moveTo, Rook, attackerColor, false);
|
||||
} else if (moveType == queenPromotion) {
|
||||
Promote(move.moveTo, Queen, attackerColor, false);
|
||||
} else if (moveType == knightPromoCapture) {
|
||||
Promote(move.moveTo, Knight, attackerColor, true);
|
||||
} else if (moveType == bishopPromoCapture) {
|
||||
Promote(move.moveTo, Bishop, attackerColor, true);
|
||||
} else if (moveType == rookPromoCapture) {
|
||||
Promote(move.moveTo, Rook, attackerColor, true);
|
||||
} else if (moveType == queenPromoCapture) {
|
||||
Promote(move.moveTo, Queen, attackerColor, true);
|
||||
}
|
||||
|
||||
// Removing the right to castle on king movement
|
||||
|
||||
@@ -40,5 +40,6 @@ public:
|
||||
|
||||
bool InCheck(bool side);
|
||||
|
||||
void Promote(int square, int pieceType, int color, bool isCapture);
|
||||
void DoMove(Move move);
|
||||
};
|
||||
+35
-16
@@ -275,6 +275,7 @@ static void GenPawnMoves(Board &board, bool color) {
|
||||
while (pawns.GetBoard()) {
|
||||
int square = pawns.getLS1BIndex();
|
||||
int direction = color ? south : north;
|
||||
int lastRank = color ? r_1 : r_8;
|
||||
|
||||
Bitboard attacks = pawnAttacks[color][square];
|
||||
|
||||
@@ -292,28 +293,46 @@ static void GenPawnMoves(Board &board, bool color) {
|
||||
Bitboard firstAhead = Bitboard::GetSquare(square + direction) & ~board.occupied;
|
||||
Bitboard secondAhead = Bitboard::GetSquare(square + 2 * direction) & ~board.occupied;
|
||||
|
||||
while (attacks.GetBoard()) {
|
||||
int targetSquare = attacks.getLS1BIndex();
|
||||
|
||||
board.AddMove(Move(square, targetSquare, capture));
|
||||
if ((attacks & ranks[lastRank]).GetBoard()) {
|
||||
while (attacks.GetBoard()) {
|
||||
int targetSquare = attacks.getLS1BIndex();
|
||||
|
||||
for (int type = knightPromoCapture; type <= queenPromoCapture; type++) {
|
||||
board.AddMove(Move(square, targetSquare, type));
|
||||
}
|
||||
|
||||
attacks.PopBit(targetSquare);
|
||||
attacks.PopBit(targetSquare);
|
||||
}
|
||||
} else {
|
||||
while (attacks.GetBoard()) {
|
||||
int targetSquare = attacks.getLS1BIndex();
|
||||
|
||||
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));
|
||||
}
|
||||
if ((firstAhead & ranks[lastRank]).GetBoard()) {
|
||||
for (int type = knightPromotion; type <= queenPromotion; type++) {
|
||||
board.AddMove(Move(square, firstAhead.getLS1BIndex(), type));
|
||||
}
|
||||
} else {
|
||||
if (Bitboard::GetSquare(firstAhead.getLS1BIndex() & RANKS::r_7).GetBoard()) {
|
||||
if ((secondAhead).GetBoard()) {
|
||||
board.AddMove(Move(square, secondAhead.getLS1BIndex(), doublePawnPush));
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user