Fix deserialization of shogi promotions.
[tagua/yd.git] / src / moveserializer.h
blob31e609796321ec243270cce21fb4e986437cb8fb
1 /*
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.
9 */
11 #ifndef MOVESERIALIZER_H
12 #define MOVESERIALIZER_H
14 #include <QString>
15 #include "decoratedmove.h"
17 class AbstractMoveSerializer {
18 public:
19 virtual ~AbstractMoveSerializer() { }
20 virtual QString SAN() const = 0;
21 virtual DecoratedMove toDecoratedMove() const = 0;
24 template <typename Pos>
25 class MoveSerializerBase : public AbstractMoveSerializer {
26 public:
27 typedef Pos Position;
28 typedef typename Position::Move Move;
29 typedef typename Position::Piece Piece;
30 protected:
31 const Move& m_move;
32 const Position& m_ref;
34 virtual QString checkSuffix() const {
35 Pos temp(m_ref);
36 temp.move(m_move);
37 if (temp.check()) {
38 if (temp.stalled())
39 return "#";
40 else
41 return "+";
43 else
44 return "";
47 public:
48 MoveSerializerBase(const Move& move, const Position& ref)
49 : m_move(move)
50 , m_ref(ref) { }
51 virtual ~MoveSerializerBase() { }
53 virtual QString SAN() const;
54 virtual DecoratedMove toDecoratedMove() const;
57 template <typename Pos>
58 class MoveSerializer : public MoveSerializerBase<Pos> {
59 typedef Pos Position;
60 typedef typename Position::Move Move;
61 public:
62 MoveSerializer(const Move& move, const Position& ref)
63 : MoveSerializerBase<Position>(move, ref) { }
66 #endif // MOVESERIALIZER_H