2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2007 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
18 QRegExp
SAN::pattern("^([PRNBKQ])?([a-wyzA-Z]?\\d*|x\\d+)([-x@])?"
20 "([a-zA-Z]\\d+)(=?([RNBKQrnbkq]))?[+#]?[\?!]*");
21 QRegExp
SAN::kingCastlingPattern("^[oO0]-?[oO0][+#]?");
22 QRegExp
SAN::queenCastlingPattern("^[oO0]-?[oO0]-?[oO0][+#]?");
23 QRegExp
SAN::nonePattern("^none");
26 : from(Point::invalid())
27 , to(Point::invalid())
30 , castling(NoCastling
)
34 int SAN::getType(const QString
& letter
) {
38 QChar c
= letter
[0].toLower();
52 return Piece::INVALID_TYPE
;
55 void SAN::load(const QString
& str
, int& offset
, int ysize
) {
56 if (nonePattern
.indexIn(str
, offset
, QRegExp::CaretAtOffset
) != -1) {
57 from
= Point::invalid();
58 to
= Point::invalid();
59 offset
+= nonePattern
.matchedLength();
61 else if (pattern
.indexIn(str
, offset
, QRegExp::CaretAtOffset
) != -1) {
62 type
= getType(pattern
.cap(1));
63 drop
= pattern
.cap(3) == "@";
65 from
= Point::invalid();
67 from
= Point(pattern
.cap(2), ysize
);
68 to
= Point(pattern
.cap(4), ysize
);
69 promotion
= pattern
.cap(6).isEmpty() ? -1 : getType(pattern
.cap(6));
70 castling
= NoCastling
;
71 offset
+= pattern
.matchedLength();
73 else if (queenCastlingPattern
.indexIn(str
, offset
, QRegExp::CaretAtOffset
) != -1) {
76 offset
+= queenCastlingPattern
.matchedLength();
78 else if (kingCastlingPattern
.indexIn(str
, offset
, QRegExp::CaretAtOffset
) != -1) {
81 offset
+= kingCastlingPattern
.matchedLength();
84 //std::cout << "error!!!! " << str.mid(offset) << std::endl;
85 to
= Point::invalid();
89 void SAN::load(const QString
& str
, int ysize
) {
91 load(str
, offset
, ysize
);
94 std::ostream
& operator<<(std::ostream
& os
, const SAN
& move
) {
95 if (move
.castling
== SAN::KingSide
)
97 else if (move
.castling
== SAN::QueenSide
)
100 return os
<< move
.type
<< ": " << move
.from
<< " -> " << move
.to
;
105 } // namespace HLVariant