2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 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.
11 #ifndef MOVESERIALIZER_IMPL_H
12 #define MOVESERIALIZER_IMPL_H
14 #include "moveserializer.h"
17 * Assume the move has already been tested against @a ref.
18 * Calling this function on an untested or illegal move is safe but its return
20 * Do not try to call this function on an invalid move.
21 * @param ref The position in which this move shall be executed.
22 * @return A compact SAN representation for this move.
24 template <typename Pos
>
25 QString MoveSerializerBase
<Pos
>::SAN() const {
26 Q_ASSERT(m_move
.valid());
28 Piece piece
= m_ref
.get(m_move
.from
);
29 Piece captured
= m_ref
.get(m_move
.to
);
33 std::cout
<< "Move is: " << m_move
.toString(m_ref
.size().x
, m_ref
.size().y
) << std::endl
;
38 if (piece
.type() == PAWN
) {
39 if (captured
|| m_move
.type() == Move::EnPassantCapture
)
40 res
= m_move
.from
.col() + "x";
42 res
+= m_move
.to
.toString(m_ref
.size().y
);
46 if (m_move
.type() == Move::KingSideCastling
) {
49 else if (m_move
.type() == Move::QueenSideCastling
) {
53 res
= Piece::typeSymbol(piece
.type());
55 AlgebraicNotation temp
;
56 temp
.from
= m_move
.from
;
58 temp
.type
= piece
.type();
59 temp
.castling
= AlgebraicNotation::NoCastling
;
60 minimalNotation(temp
, m_ref
);
62 res
+= temp
.from
.toString(m_ref
.size().y
);
63 if (captured
) res
+= "x";
64 res
+= temp
.to
.toString(m_ref
.size().y
);
68 if (m_move
.type() == Move::Promotion
)
69 res
+= "=" + Piece::typeSymbol(m_move
.promotionType
);
71 return res
+ checkSuffix();
74 template <typename Pos
>
75 DecoratedMove MoveSerializerBase
<Pos
>::toDecoratedMove() const {
76 static QRegExp
reg("[KQRBNP]");
80 while(reg
.indexIn(move
, x
) != -1) {
82 mv
.push_back(MovePart(move
.mid(x
, reg
.pos()-x
)));
83 switch(move
[reg
.pos()].toAscii()) {
85 mv
.push_back(MovePart("king", MovePart::Figurine
));
88 mv
.push_back(MovePart("queen", MovePart::Figurine
));
91 mv
.push_back(MovePart("rook", MovePart::Figurine
));
94 mv
.push_back(MovePart("bishop", MovePart::Figurine
));
97 mv
.push_back(MovePart("knight", MovePart::Figurine
));
100 mv
.push_back(MovePart("pawn", MovePart::Figurine
));
103 x
= reg
.pos() + reg
.matchedLength();
106 mv
.push_back(MovePart(move
.mid(x
)));
110 #endif // MOVESERIALIZER_IMPL_H