[gnome-chess] Fix AI hang when Phalanx attempts to promote



commit d190d8bbdb78697774eae854c398e7fa15893a25
Author: Michael Catanzaro <mike catanzaro gmail com>
Date:   Sat Mar 23 21:56:37 2013 -0500

    Fix AI hang when Phalanx attempts to promote
    
    Also, add two promotion tests
    
    https://bugzilla.gnome.org/show_bug.cgi?id=696475

 src/chess-game.vala      |  4 ++++
 src/test-chess-game.vala | 11 +++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/src/chess-game.vala b/src/chess-game.vala
index 39e386f..557acbc 100644
--- a/src/chess-game.vala
+++ b/src/chess-game.vala
@@ -1091,18 +1091,22 @@ public class ChessState
                 switch (move[i])
                 {
                 case 'q':
+                case 'Q':
                     promotion_type = PieceType.QUEEN;
                     i++;
                     break;
                 case 'n':
+                case 'N':
                     promotion_type = PieceType.KNIGHT;
                     i++;
                     break;
                 case 'r':
+                case 'R':
                     promotion_type = PieceType.ROOK;
                     i++;
                     break;
                 case 'b':
+                case 'B':
                     promotion_type = PieceType.BISHOP;
                     i++;
                     break;
diff --git a/src/test-chess-game.vala b/src/test-chess-game.vala
index 89f5e53..c1c209e 100644
--- a/src/test-chess-game.vala
+++ b/src/test-chess-game.vala
@@ -5,7 +5,8 @@ class GlChess
 
     private static void test_good_move (string fen, string move, string result_fen,
                                         ChessResult result = ChessResult.IN_PROGRESS,
-                                        ChessRule rule = ChessRule.CHECKMATE)
+                                        ChessRule rule = ChessRule.CHECKMATE,
+                                        bool verify_san = false)
     {
         ChessState state = new ChessState (fen);
         test_count++;
@@ -23,7 +24,9 @@ class GlChess
             return;
         }
 
-        if (state.last_move.get_san () != move)
+        // We don't typically want to test this since get_san returns exactly one canonical SAN,
+        // but some test cases want to verify that slightly different notations are accepted.
+        if (verify_san && state.last_move.get_san () != move)
         {
             stderr.printf ("%d. FAIL %s + %s has SAN move %s\n", test_count, fen, move, 
state.last_move.get_san ());
             failure_count++;
@@ -72,6 +75,10 @@ class GlChess
         /* Pawn promotion */
         test_good_move ("8/P7/8/8/8/8/8/8 w - - 0 1", "a8=Q",
                         "Q7/8/8/8/8/8/8/8 b - - 0 1");
+        test_good_move ("8/P7/8/8/8/8/8/8 w - - 0 1", "a7a8q",
+                        "Q7/8/8/8/8/8/8/8 b - - 0 1");
+        test_good_move ("8/P7/8/8/8/8/8/8 w - - 0 1", "a7a8N",
+                        "N7/8/8/8/8/8/8/8 b - - 0 1");
 
         /* En passant */
         test_good_move ("8/8/8/pP6/8/8/8/8 w - a6 0 1", "bxa6",


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