[gnome-chess] Show better move description for en passant captures
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chess] Show better move description for en passant captures
- Date: Tue, 24 Apr 2018 16:52:29 +0000 (UTC)
commit 9b41b9bef7c6b7bc851fcb2ecbbc2e3e9d1afcc4
Author: Michael Catanzaro <mcatanzaro igalia com>
Date: Tue Apr 24 10:47:46 2018 -0500
Show better move description for en passant captures
The current description is wrong since it says the captured piece was at
the current location of the capturing piece, but that's not true for en
passant captures.
Also, this might possibly help users realize that en passant is not a bug.
lib/chess-move.vala | 2 ++
lib/chess-state.vala | 3 +++
src/gnome-chess.vala | 39 +++++++++++++++++++++------------------
3 files changed, 26 insertions(+), 18 deletions(-)
---
diff --git a/lib/chess-move.vala b/lib/chess-move.vala
index 6b6b021..cc5f58b 100644
--- a/lib/chess-move.vala
+++ b/lib/chess-move.vala
@@ -22,6 +22,7 @@ public class ChessMove : Object
public int f1;
public bool ambiguous_rank;
public bool ambiguous_file;
+ public bool en_passant;
public CheckState check_state;
public string get_lan ()
@@ -135,6 +136,7 @@ public class ChessMove : Object
move.f1 = f1;
move.ambiguous_rank = ambiguous_rank;
move.ambiguous_file = ambiguous_file;
+ move.en_passant = en_passant;
move.check_state = check_state;
return move;
}
diff --git a/lib/chess-state.vala b/lib/chess-state.vala
index 6d297ad..c5b6a1f 100644
--- a/lib/chess-state.vala
+++ b/lib/chess-state.vala
@@ -317,6 +317,7 @@ public class ChessState : Object
/* Check special moves */
int rook_start = -1, rook_end = -1;
bool is_promotion = false;
+ bool en_passant = false;
bool ambiguous_rank = false;
bool ambiguous_file = false;
switch (piece.type)
@@ -325,6 +326,7 @@ public class ChessState : Object
/* Check if taking an marched pawn */
if (victim == null && end == en_passant_index)
{
+ en_passant = true;
victim_index = get_index (r1 == 2 ? 3 : 4, f1);
victim = board[victim_index];
}
@@ -543,6 +545,7 @@ public class ChessState : Object
last_move.f1 = f1;
last_move.ambiguous_rank = ambiguous_rank;
last_move.ambiguous_file = ambiguous_file;
+ last_move.en_passant = en_passant;
last_move.check_state = check_state;
return true;
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 9bae932..12d40c5 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -1034,7 +1034,27 @@ Copyright © 2015–2016 Sahil Sareen""";
switch (scene.move_format)
{
case "human":
- if (move.castling_rook == null)
+ if (move.en_passant)
+ {
+ if (move.r0 < move.r1)
+ move_text = _("White pawn captures black pawn en passant");
+ else
+ move_text = _("Black pawn captures white pawn en passant");
+ }
+ else if (move.castling_rook != null)
+ {
+ if (move.f0 < move.f1 && move.r0 == 0)
+ move_text = _("White castles kingside");
+ else if (move.f1 < move.f0 && move.r0 == 0)
+ move_text = _("White castles queenside");
+ else if (move.f0 < move.f1 && move.r0 == 7)
+ move_text = _("Black castles kingside");
+ else if (move.f1 < move.f0 && move.r0 == 7)
+ move_text = _("Black castles queenside");
+ else
+ assert_not_reached ();
+ }
+ else
{
int index;
if (move.victim == null)
@@ -1049,23 +1069,6 @@ Copyright © 2015–2016 Sahil Sareen""";
var end = "%c%d".printf ('a' + move.f1, move.r1 + 1);
move_text = _(human_descriptions[index]).printf (start, end);
}
- else if (move.f0 < move.f1 && move.r0 == 0)
- {
- move_text = _("White castles kingside");
- }
- else if (move.f1 < move.f0 && move.r0 == 0)
- {
- move_text = _("White castles queenside");
- }
- else if (move.f0 < move.f1 && move.r0 == 7)
- {
- move_text = _("Black castles kingside");
- }
- else if (move.f1 < move.f0 && move.r0 == 7)
- {
- move_text = _("Black castles queenside");
- }
- else assert_not_reached ();
break;
case "san":
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]