[gnome-games] glchess: Can't castle once rook is taken



commit a98e2e336cbb1f398264cb5bb3978e99b8acd4d1
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri Jul 13 09:50:56 2012 +1200

    glchess: Can't castle once rook is taken

 glchess/src/chess-game.vala |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
---
diff --git a/glchess/src/chess-game.vala b/glchess/src/chess-game.vala
index 09d2541..86cc5a4 100644
--- a/glchess/src/chess-game.vala
+++ b/glchess/src/chess-game.vala
@@ -595,7 +595,7 @@ public class ChessState
                 }
 
                 var rook = board[rook_start];
-                if (rook == null)
+                if (rook == null || rook.type != PieceType.ROOK || rook.color != color)
                     return false;
 
                 /* Check rook can move */
@@ -701,6 +701,18 @@ public class ChessState
                     can_castle_kingside[color] = false;
             }
         }
+        /* Can't castle once the rooks have been captured */
+        else if (victim != null && victim.type == PieceType.ROOK)
+        {
+            int base_rank = opponent_color == Color.WHITE ? 0 : 7;
+            if (r1 == base_rank)
+            {
+                if (f1 == 0)
+                    can_castle_queenside[opponent_color] = false;
+                else if (f1 == 7)
+                    can_castle_kingside[opponent_color] = false;
+            }
+        }
 
         /* Pawn square moved over is vulnerable */
         if (piece.type == PieceType.PAWN && over_mask != 0)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]