From 3c9ef0079169895097dd605a8c1495f656110502 Mon Sep 17 00:00:00 2001 From: Paolo Capriotti Date: Thu, 2 Aug 2007 02:28:19 +0200 Subject: [PATCH] Fixed shogi borderCoords and serialization. --- src/hlvariant/shogi/serializer.h | 32 +++++++++++++++++------ src/hlvariant/shogi/shogiban.h | 55 ++++++++++++++++++++++++++++++++++++++++ src/hlvariant/shogi/variant.h | 3 ++- 3 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 src/hlvariant/shogi/shogiban.h diff --git a/src/hlvariant/shogi/serializer.h b/src/hlvariant/shogi/serializer.h index d3f3dc7..4851c9a 100644 --- a/src/hlvariant/shogi/serializer.h +++ b/src/hlvariant/shogi/serializer.h @@ -35,7 +35,7 @@ protected: virtual bool isAmbiguous(const Move& move, const GameState& ref) const; virtual QString square(const Point& p, const Point& size) const; - virtual QChar symbol(typename Piece::Type type) const; + virtual QString symbol(const Piece& piece) const; public: Serializer(int rep); virtual ~Serializer(); @@ -82,7 +82,15 @@ bool Serializer::isAmbiguous(const Move& move, const GameState& r template QString Serializer::square(const Point& p, const Point& size) const { - return QString::number(size.x - p.x) + QString(p.y + 'a'); + QString res = QString::number(size.x - p.x); + if (m_rep == DECORATED) { + res += "{num_" + QString::number(p.y + 1) + "}"; + } + else { + res += QString(p.y + 'a'); + } + + return res; } @@ -98,7 +106,7 @@ QString Serializer::serialize(const Move& move, const GameState& if (piece.promoted()) res += "+"; - res += symbol(piece.type()); + res += symbol(piece); if (ambiguous) { res += square(move.from(), ref.board().size()); @@ -125,11 +133,19 @@ QString Serializer::serialize(const Move& move, const GameState& } template -QChar Serializer::symbol(typename Piece::Type type) const { - if (type == Piece::KNIGHT) - return 'N'; - else - return Piece::typeName(type)[0].toUpper(); +QString Serializer::symbol(const Piece& piece) const { + if (m_rep == DECORATED) { + QString res = "{"; + if (piece.promoted()) + res += "p_"; + return res + piece.typeName() + "}"; + } + else { + if (piece.type() == Piece::KNIGHT) + return "N"; + else + return piece.typeName()[0].toUpper(); + } } template diff --git a/src/hlvariant/shogi/shogiban.h b/src/hlvariant/shogi/shogiban.h new file mode 100644 index 0000000..416298f --- /dev/null +++ b/src/hlvariant/shogi/shogiban.h @@ -0,0 +1,55 @@ +#ifndef HLVARIANT__SHOGI__SHOGIBAN_H +#define HLVARIANT__SHOGI__SHOGIBAN_H + +#include "../customboard.h" + +namespace HLVariant { +namespace Shogi { + +template +class ShogiBan : public CustomBoard { +public: + typedef _Piece Piece; + typedef CustomBoard Base; + + QStringList borderCoords() const; +}; + +// IMPLEMENTATION + +template +QStringList ShogiBan::borderCoords() const { + QStringList retv; + for (int i = this->size().y; i > 0; i--) + retv += QString::number(i); + + switch (this->size().x) { + default: + case 9: + retv << QChar(0x4e5d); + case 8: + retv << QChar(0x516b); + case 7: + retv << QChar(0x4e03); + case 6: + retv << QChar(0x516d); + case 5: + retv << QChar(0x4e94); + case 4: + retv << QChar(0x56db); + case 3: + retv << QChar(0x4e09); + case 2: + retv << QChar(0x4e8c); + case 1: + retv << QChar(0x4e00); + } + + return retv + retv; +} + +} // namespace Shogi +} // namespace HLVariant + +#endif // HLVARIANT__SHOGI__SHOGIBAN_H + diff --git a/src/hlvariant/shogi/variant.h b/src/hlvariant/shogi/variant.h index 8a7acd8..1aa1114 100644 --- a/src/hlvariant/shogi/variant.h +++ b/src/hlvariant/shogi/variant.h @@ -12,6 +12,7 @@ #define HLVARIANT__SHOGI__VARIANT_H #include "piece.h" +#include "shogiban.h" #include "../chess/move.h" #include "../crazyhouse/move.h" #include "gamestate.h" @@ -26,7 +27,7 @@ namespace Shogi { struct TAGUA_EXPORT Variant { typedef Crazyhouse::MoveMixin Move; - typedef GameState, Move> GameState; + typedef GameState, Move> GameState; typedef LegalityCheck LegalityCheck; typedef Serializer Serializer; typedef DropAnimatorMixin > Animator; -- 2.11.4.GIT