Ver código fonte

fixed castling bug

nicolaswinkler 7 anos atrás
pai
commit
efffd6fb2d
1 arquivos alterados com 6 adições e 4 exclusões
  1. 6 4
      src/MoveGeneration.cpp

+ 6 - 4
src/MoveGeneration.cpp

@@ -354,9 +354,10 @@ void chessy::generateCastling(const ChessGame& cg, std::vector<Move>& moves)
     Bitboard allOccupied = b.getOccupied();
     if (cg.getCanCastleKingSide(side)) {
         Bitboard target = king.bits >> 2; // move king to the right
-        Bitboard rook = king.bits << 3;
+        Bitboard rook = king.bits >> 3;
         Bitboard rookTarget = king.bits >> 1;
-        if (!(target & allOccupied) &&
+        if ((rook & b.getRooks<side>()) &&
+            !(target & allOccupied) &&
             !(rookTarget & allOccupied)) {
             moves.emplace_back(king.getLeastSignificantBit(),
                 target.getLeastSignificantBit(), true);
@@ -364,9 +365,10 @@ void chessy::generateCastling(const ChessGame& cg, std::vector<Move>& moves)
     }
     if (cg.getCanCastleQueenSide(side)) {
         Bitboard target = king.bits << 2; // move king to the left
-        Bitboard rook = king.bits >> 3;
+        Bitboard rook = king.bits << 4;
         Bitboard rookTarget = king.bits << 1;
-        if (!(target & allOccupied) &&
+        if ((rook & b.getRooks<side>()) &&
+            !(target & allOccupied) &&
             !(rookTarget & allOccupied)) {
             moves.emplace_back(king.getLeastSignificantBit(),
                 target.getLeastSignificantBit(), true);