From 30840379a2a6269699350b55b314d29c2ee444b0 Mon Sep 17 00:00:00 2001
From: Paolo Capriotti
Date: Fri, 27 Jul 2007 11:12:30 +0200
Subject: [PATCH] Fixed bug in algebraic notation -> move conversion.
Moves like 'a2b1q' are now correctly understood.
---
src/algebraicnotation.cpp | 9 +++------
src/variants/xchess/position.h | 2 +-
2 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/src/algebraicnotation.cpp b/src/algebraicnotation.cpp
index 06075e6..996dd6e 100644
--- a/src/algebraicnotation.cpp
+++ b/src/algebraicnotation.cpp
@@ -16,10 +16,10 @@
//BEGIN AlgebraicNotation
-// 1 2 3
+// 1 2 3
QRegExp AlgebraicNotation::pattern("^([PRNBKQ])?([a-wyzA-Z]?\\d*|x\\d+)([-x@])?"
-// 4 5 6
- "([a-zA-Z]\\d+)(=([RNBKQ]))?[+#]?[\?!]*");
+// 4 5 6
+ "([a-zA-Z]\\d+)(=?([RNBKQrnbkq]))?[+#]?[\?!]*");
QRegExp AlgebraicNotation::kingCastlingPattern("^[oO0]-?[oO0][+#]?");
QRegExp AlgebraicNotation::queenCastlingPattern("^[oO0]-?[oO0]-?[oO0][+#]?");
QRegExp AlgebraicNotation::nonePattern("^none");
@@ -63,18 +63,15 @@ void AlgebraicNotation::init(const QString& str, int& offset, int ysize) {
offset += nonePattern.matchedLength();
}
else if (pattern.indexIn(str, offset, QRegExp::CaretAtOffset) != -1) {
- //std::cout << "matched " << pattern.cap(0) << std::endl;
type = ChessPiece::getType(pattern.cap(1));
drop = pattern.cap(3) == "@";
if (drop)
from = Point::invalid();
else
from = Point(pattern.cap(2), ysize);
-
to = Point(pattern.cap(4), ysize);
promotion = pattern.cap(6).isEmpty() ? -1 : ChessPiece::getType(pattern.cap(6));
castling = NoCastling;
-
offset += pattern.matchedLength();
}
else if (queenCastlingPattern.indexIn(str, offset, QRegExp::CaretAtOffset) != -1) {
diff --git a/src/variants/xchess/position.h b/src/variants/xchess/position.h
index 5a785c9..40e1275 100644
--- a/src/variants/xchess/position.h
+++ b/src/variants/xchess/position.h
@@ -494,7 +494,7 @@ M Position::getMove(const AlgebraicNotation& san, bool& ok) const {
}
if (san.from.valid()) {
- candidate = M(san.from, san.to);
+ candidate = M(san.from, san.to, static_cast(san.promotion));
}
else {
for (Point i = first(); i <= last(); i = next(i)) {
--
2.11.4.GIT