[gnome-chess] Fix being able to castle when square being moved over is threatened by a pawn. Test case done by Mic



commit f0276e497f16f6c9f2b3983685c8ce9ccc4208e9
Author: Robert Ancell <robert ancell canonical com>
Date:   Tue Jan 8 14:09:08 2013 +1300

    Fix being able to castle when square being moved over is threatened by a pawn.
    Test case done by Michael Catanzaro, thanks!

 src/chess-game.vala      |    7 ++-----
 src/test-chess-game.vala |    2 ++
 2 files changed, 4 insertions(+), 5 deletions(-)
---
diff --git a/src/chess-game.vala b/src/chess-game.vala
index a29e745..c3b7d78 100644
--- a/src/chess-game.vala
+++ b/src/chess-game.vala
@@ -628,11 +628,8 @@ public class ChessState
                     return false;
 
                 /* Square moved across can't be under attack */
-                for (int i = 0; i < 64; i++)
-                {
-                    if (move_with_coords (opponent, get_rank (i), get_file (i), get_rank (rook_end), get_file (rook_end), PieceType.QUEEN, false, false))
-                        return false;
-                }
+                if (!move_with_coords (player, r0, f0, get_rank (rook_end), get_file (rook_end), PieceType.QUEEN, false, true))
+                    return false;
             }
             break;
         default:
diff --git a/src/test-chess-game.vala b/src/test-chess-game.vala
index 1e68ae0..0ad0b0f 100644
--- a/src/test-chess-game.vala
+++ b/src/test-chess-game.vala
@@ -99,6 +99,8 @@ class GlChess
 
         /* Can't move across square that would put into check */
         test_bad_move ("5r2/8/8/8/8/8/8/4K2R w K - 0 1", "O-O");
+        test_bad_move ("8/8/8/8/8/8/6p1/4K2R w K - 0 1", "O-O");
+        test_bad_move ("8/8/8/8/8/8/4p3/R3K3 w Q - 0 1", "O-O-O");
 
         /* Can't move into check */
         test_bad_move ("4r3/8/8/8/8/8/4R3/4K3 w - - 0 1", "e2f2");



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