[gnome-chess/gnome-3-8] Insufficient material fixes
- From: Jason Clinton <jclinton src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chess/gnome-3-8] Insufficient material fixes
- Date: Mon, 15 Apr 2013 04:54:03 +0000 (UTC)
commit ae752829e774cfd3112f0b72aa96119b457581bf
Author: Michael Catanzaro <mike catanzaro gmail com>
Date: Wed Jan 2 19:09:32 2013 -0600
Insufficient material fixes
Although two knights cannot FORCE a checkmate, the opponent can
blunder. This position is not a draw.
Also, if each side has one minor piece (unless they are two
Bishops on the same color) the game is - surprisingly - not drawn.
With the extra piece you could wind up in a checkmate that's not
possible if the King is on his own.
https://bugzilla.gnome.org/show_bug.cgi?id=691053
(cherry picked from commit 3a0a4d6a896474a8f6681442f958be0069c8f83f)
src/chess-game.vala | 10 ++++++++--
src/test-chess-game.vala | 19 ++++++++++++++++++-
2 files changed, 26 insertions(+), 3 deletions(-)
---
diff --git a/src/chess-game.vala b/src/chess-game.vala
index 96c01e7..39e386f 100644
--- a/src/chess-game.vala
+++ b/src/chess-game.vala
@@ -970,8 +970,8 @@ public class ChessState
}
}
- /* Three knights versus king can checkmate */
- if (white_knight_count > 2 || black_knight_count > 2)
+ /* Two knights versus king can checkmate (though not against an optimal opponent) */
+ if (white_knight_count > 1 || black_knight_count > 1)
return true;
/* Bishop and knight versus king can checkmate */
@@ -985,6 +985,12 @@ public class ChessState
return true;
if (black_bishop_on_white_square && black_bishop_on_black_square)
return true;
+
+ /* King and minor piece vs. King and knight is surprisingly not a draw */
+ if ((white_bishop_count > 0 || white_knight_count > 0) && black_knight_count > 0)
+ return true;
+ if ((black_bishop_count > 0 || black_knight_count > 0) && white_knight_count > 0)
+ return true;
}
return false;
diff --git a/src/test-chess-game.vala b/src/test-chess-game.vala
index eb339d7..89f5e53 100644
--- a/src/test-chess-game.vala
+++ b/src/test-chess-game.vala
@@ -127,10 +127,27 @@ class GlChess
test_good_move ("k7/8/7R/8/8/8/8/1R6 w - - 0 1", "Rh7",
"k7/7R/8/8/8/8/8/1R6 b - - 1 1", ChessResult.DRAW, ChessRule.STALEMATE);
- /* Insufficient material */
+ /* Insufficient material - King vs. King */
test_good_move ("k7/7p/7K/8/8/8/8/8 w - - 0 1", "Kxh7",
"k7/7K/8/8/8/8/8/8 b - - 0 1", ChessResult.DRAW, ChessRule.INSUFFICIENT_MATERIAL);
+ /* Insufficient material - King and knight vs. King */
+ test_good_move ("k7/7p/7K/8/8/8/8/7N w - - 0 1", "Kxh7",
+ "k7/7K/8/8/8/8/8/7N b - - 0 1", ChessResult.DRAW, ChessRule.INSUFFICIENT_MATERIAL);
+ /* Sufficient if a knight on each side */
+ test_good_move("k7/7p/7K/8/8/8/8/6Nn w - - 0 1", "Kxh7",
+ "k7/7K/8/8/8/8/8/6Nn b - - 0 1");
+ /* A bishop would suffice as well */
+ test_good_move("k7/7p/7K/8/8/8/8/6Nb w - - 0 1", "Kxh7",
+ "k7/7K/8/8/8/8/8/6Nb b - - 0 1");
+
+ /* Insufficient material - King and n same-color bishops vs. King and n other-color bishops */
+ test_good_move("k2b1b1b/6bp/7K/5B1B/8/8/8/8 w - - 0 1", "Kxh7",
+ "k2b1b1b/6bK/8/5B1B/8/8/8/8 b - - 0 1", ChessResult.DRAW,
ChessRule.INSUFFICIENT_MATERIAL);
+ /* Sufficient if a bishop is on each color */
+ test_good_move("k2b1b1b/6bp/7K/6BB/8/8/8/8 w - - 0 1", "Kxh7",
+ "k2b1b1b/6bK/8/6BB/8/8/8/8 b - - 0 1");
+
// FIXME: Need to be able to test claim draw
/* Claim draw due to 50 move rule */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]