Procházet zdrojové kódy

promotions really fixed now

Nicolas Winkler před 7 roky
rodič
revize
513fd6c6d2
2 změnil soubory, kde provedl 14 přidání a 2 odebrání
  1. 12 2
      src/ChessGame.cpp
  2. 2 0
      src/ChessGame.h

+ 12 - 2
src/ChessGame.cpp

@@ -165,8 +165,16 @@ UndoInfo ChessGame::doMove(const MoveInfo& mi)
     ui.before = b;
 
     Bitboard target = Bitboard::fromIndex(mi.move.destination);
-    b &= ~Bitboard::fromIndex(mi.move.origin);
-    b |= target;
+    b ^= Bitboard::fromIndex(mi.move.origin);
+    if (mi.move.promotion == PAWN) {
+        b |= target;
+        ui.promotion = PAWN;
+    }
+    else {
+        ui.promotion = mi.move.promotion;
+        ui.promotionBefore = board.getBitboards(turn)[ui.promotion];
+        board.getBitboards(turn)[ui.promotion] |= target;
+    }
 
     ui.captured = PieceType::EMPTY;
     for (int i = 0; i < 6; i++) {
@@ -198,6 +206,8 @@ void ChessGame::undoMove(const UndoInfo& ui)
     b = ui.before;
     if (ui.captured != PieceType::EMPTY)
         board.getBitboards(otherSide(turn))[ui.captured] = ui.beforeCaptured;
+    if (ui.promotion != PieceType::PAWN)
+        board.getBitboards(turn)[ui.promotion] = ui.promotionBefore;
     moveCount--;
     reversibleHalfMoves = ui.reversibleHalfMoves;
     castlingRights = ui.castlingRights;

+ 2 - 0
src/ChessGame.h

@@ -41,8 +41,10 @@ struct chessy::UndoInfo
 {
     Bitboard before;
     Bitboard beforeCaptured;
+    Bitboard promotionBefore;
     PieceType type;
     PieceType captured;
+    PieceType promotion;
     uint8_t reversibleHalfMoves;
     uint8_t castlingRights;
 };