Added CustomBoard.
[tagua/yd.git] / src / hlvariant / crazyhouse / serializer.h
blob13561f656e8be914a4f3c2ec5adbb71b87862539
1 /*
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.
9 */
11 #ifndef HLVARIANT__CRAZYHOUSE__SERIALIZER_H
12 #define HLVARIANT__CRAZYHOUSE__SERIALIZER_H
14 #include "../chess/serializer.h"
16 namespace HLVariant {
17 namespace Crazyhouse {
19 template <typename MoveGenerator>
20 class Serializer : public Chess::Serializer<MoveGenerator> {
21 typedef Chess::Serializer<MoveGenerator> Base;
22 typedef typename Base::GameState GameState;
23 typedef typename Base::Piece Piece;
24 typedef typename Base::Move Move;
25 protected:
26 using Base::m_rep;
27 public:
28 Serializer(int rep);
29 virtual QString serialize(const Move& move, const GameState& ref);
32 // IMPLEMENTATION
34 template <typename MoveGenerator>
35 Serializer<MoveGenerator>::Serializer(int rep)
36 : Base(rep) { }
38 template <typename MoveGenerator>
39 QString Serializer<MoveGenerator>::serialize(const Move& move, const GameState& ref) {
40 if (move.drop() == Piece()) {
41 return Base::serialize(move, ref);
44 QString res;
45 switch (m_rep) {
46 case Base::SIMPLE:
47 case Base::COMPACT:
48 res = symbol(move.drop().type()).toUpper();
49 case Base::DECORATED:
50 res = "{" + move.drop().typeName() + '}';
53 return res + '@' + move.to().toString(ref.board().size().y) + suffix(move, ref);
57 } // namespace Crazyhouse
58 } // namespace HLVariant
60 #endif // HLVARIANT__CRAZYHOUSE__SERIALIZER_H