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;
|
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) {
|
void Board::DoMove(Move move) {
|
||||||
enPassantTarget = a1; // resetting (a1 is impossible)
|
enPassantTarget = a1; // resetting (a1 is impossible)
|
||||||
uint16_t moveType = move.moveFlags;
|
uint16_t moveType = move.moveFlags;
|
||||||
@@ -292,13 +306,15 @@ void Board::DoMove(Move move) {
|
|||||||
|
|
||||||
int direction = attackerColor ? south : north;
|
int direction = attackerColor ? south : north;
|
||||||
|
|
||||||
|
|
||||||
pieces[attackerType].PopBit(move.moveFrom);
|
pieces[attackerType].PopBit(move.moveFrom);
|
||||||
colors[attackerColor].PopBit(move.moveFrom);
|
colors[attackerColor].PopBit(move.moveFrom);
|
||||||
occupied.PopBit(move.moveFrom);
|
occupied.PopBit(move.moveFrom);
|
||||||
|
|
||||||
pieces[attackerType].SetBit(move.moveTo);
|
if (moveType < knightPromotion) {
|
||||||
colors[attackerColor].SetBit(move.moveTo);
|
pieces[attackerType].SetBit(move.moveTo);
|
||||||
|
colors[attackerColor].SetBit(move.moveTo);
|
||||||
|
}
|
||||||
|
|
||||||
if (moveType == quiet) {
|
if (moveType == quiet) {
|
||||||
occupied.SetBit(move.moveTo);
|
occupied.SetBit(move.moveTo);
|
||||||
} else if (moveType == doublePawnPush) {
|
} else if (moveType == doublePawnPush) {
|
||||||
@@ -332,6 +348,22 @@ void Board::DoMove(Move move) {
|
|||||||
pieces[Rook].SetBit(rookSquare - 2);
|
pieces[Rook].SetBit(rookSquare - 2);
|
||||||
colors[attackerColor].SetBit(rookSquare - 2);
|
colors[attackerColor].SetBit(rookSquare - 2);
|
||||||
occupied.SetBit(rookSquare);
|
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
|
// Removing the right to castle on king movement
|
||||||
|
|||||||
@@ -40,5 +40,6 @@ public:
|
|||||||
|
|
||||||
bool InCheck(bool side);
|
bool InCheck(bool side);
|
||||||
|
|
||||||
|
void Promote(int square, int pieceType, int color, bool isCapture);
|
||||||
void DoMove(Move move);
|
void DoMove(Move move);
|
||||||
};
|
};
|
||||||
+35
-16
@@ -275,6 +275,7 @@ static void GenPawnMoves(Board &board, bool color) {
|
|||||||
while (pawns.GetBoard()) {
|
while (pawns.GetBoard()) {
|
||||||
int square = pawns.getLS1BIndex();
|
int square = pawns.getLS1BIndex();
|
||||||
int direction = color ? south : north;
|
int direction = color ? south : north;
|
||||||
|
int lastRank = color ? r_1 : r_8;
|
||||||
|
|
||||||
Bitboard attacks = pawnAttacks[color][square];
|
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 firstAhead = Bitboard::GetSquare(square + direction) & ~board.occupied;
|
||||||
Bitboard secondAhead = Bitboard::GetSquare(square + 2 * direction) & ~board.occupied;
|
Bitboard secondAhead = Bitboard::GetSquare(square + 2 * direction) & ~board.occupied;
|
||||||
|
|
||||||
while (attacks.GetBoard()) {
|
if ((attacks & ranks[lastRank]).GetBoard()) {
|
||||||
int targetSquare = attacks.getLS1BIndex();
|
while (attacks.GetBoard()) {
|
||||||
|
int targetSquare = attacks.getLS1BIndex();
|
||||||
board.AddMove(Move(square, targetSquare, capture));
|
|
||||||
|
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()) {
|
if (firstAhead.GetBoard()) {
|
||||||
board.AddMove(Move(square, firstAhead.getLS1BIndex(), quiet));
|
if ((firstAhead & ranks[lastRank]).GetBoard()) {
|
||||||
|
for (int type = knightPromotion; type <= queenPromotion; type++) {
|
||||||
if (color == White) {
|
board.AddMove(Move(square, firstAhead.getLS1BIndex(), type));
|
||||||
if (Bitboard::GetSquare(firstAhead.getLS1BIndex() & RANKS::r_2).GetBoard()) {
|
|
||||||
if ((secondAhead).GetBoard()) {
|
|
||||||
board.AddMove(Move(square, secondAhead.getLS1BIndex(), doublePawnPush));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (Bitboard::GetSquare(firstAhead.getLS1BIndex() & RANKS::r_7).GetBoard()) {
|
board.AddMove(Move(square, firstAhead.getLS1BIndex(), quiet));
|
||||||
if ((secondAhead).GetBoard()) {
|
}
|
||||||
board.AddMove(Move(square, secondAhead.getLS1BIndex(), doublePawnPush));
|
}
|
||||||
}
|
|
||||||
|
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