From 9b9927a5c4a79fefa83512d45f9951feb6ac4924 Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Sun, 13 Jan 2008 16:04:34 +0100 Subject: [PATCH] refresh bdc45694d411cad215e68161e75bb9f1a8a39e47 first rework with variant types --- src/core/piece.cpp | 3 ++- src/core/piece.h | 6 ++--- src/variants/shogi/CMakeLists.txt | 18 +++++---------- src/variants/shogi/behaviour.cpp | 5 +++-- src/variants/shogi/faces/CMakeLists.txt | 21 +++++++++++++++++ src/variants/shogi/{ => faces}/bishop.cpp | 4 +++- src/variants/shogi/{ => faces}/bishop.h | 8 ++++--- src/variants/shogi/{ => faces}/dragonhorse.cpp | 4 +++- src/variants/shogi/{ => faces}/dragonhorse.h | 8 ++++--- src/variants/shogi/{ => faces}/dragonking.cpp | 4 +++- src/variants/shogi/{ => faces}/dragonking.h | 8 ++++--- src/variants/shogi/{ => faces}/gold.cpp | 4 +++- src/variants/shogi/{ => faces}/gold.h | 8 ++++--- src/variants/shogi/{ => faces}/king.cpp | 2 ++ src/variants/shogi/{ => faces}/king.h | 8 ++++--- src/variants/shogi/{ => faces}/knight.cpp | 2 ++ src/variants/shogi/{ => faces}/knight.h | 8 ++++--- src/variants/shogi/{ => faces}/lance.cpp | 4 +++- src/variants/shogi/{ => faces}/lance.h | 8 ++++--- src/variants/shogi/{ => faces}/pawn.cpp | 2 ++ src/variants/shogi/{ => faces}/pawn.h | 8 ++++--- src/variants/shogi/{ => faces}/rook.cpp | 4 +++- src/variants/shogi/{ => faces}/rook.h | 8 ++++--- src/variants/shogi/{ => faces}/silver.cpp | 4 +++- src/variants/shogi/{ => faces}/silver.h | 8 ++++--- src/variants/shogi/piece.cpp | 31 -------------------------- src/variants/shogi/piece.h | 29 ------------------------ src/variants/shogi/pieces/CMakeLists.txt | 18 +++++++++++++++ src/variants/shogi/pieces/pawn.cpp | 14 ++++++++++++ src/variants/shogi/{ => pieces}/pawn.h | 10 ++++----- src/variants/shogi/shogi.cpp | 20 ++++++++++------- src/variants/shogi/state.cpp | 1 - src/variants/shogi/state.h | 1 + src/variants/shogi/type.cpp | 28 +++++++++++++++++++++++ src/variants/shogi/{dragonking.h => type.h} | 15 ++++++++----- src/variants/shogi/types.h | 18 +++++++-------- src/variants/shogi/validator.cpp | 1 - 37 files changed, 206 insertions(+), 147 deletions(-) create mode 100644 src/variants/shogi/faces/CMakeLists.txt rename src/variants/shogi/{ => faces}/bishop.cpp (93%) rename src/variants/shogi/{ => faces}/bishop.h (86%) rename src/variants/shogi/{ => faces}/dragonhorse.cpp (93%) rename src/variants/shogi/{ => faces}/dragonhorse.h (85%) rename src/variants/shogi/{ => faces}/dragonking.cpp (93%) copy src/variants/shogi/{ => faces}/dragonking.h (85%) rename src/variants/shogi/{ => faces}/gold.cpp (94%) rename src/variants/shogi/{ => faces}/gold.h (87%) rename src/variants/shogi/{ => faces}/king.cpp (97%) rename src/variants/shogi/{ => faces}/king.h (87%) rename src/variants/shogi/{ => faces}/knight.cpp (98%) rename src/variants/shogi/{ => faces}/knight.h (86%) rename src/variants/shogi/{ => faces}/lance.cpp (94%) rename src/variants/shogi/{ => faces}/lance.h (87%) rename src/variants/shogi/{ => faces}/pawn.cpp (98%) copy src/variants/shogi/{ => faces}/pawn.h (87%) rename src/variants/shogi/{ => faces}/rook.cpp (93%) rename src/variants/shogi/{ => faces}/rook.h (87%) rename src/variants/shogi/{ => faces}/silver.cpp (94%) rename src/variants/shogi/{ => faces}/silver.h (87%) delete mode 100644 src/variants/shogi/piece.cpp delete mode 100644 src/variants/shogi/piece.h create mode 100644 src/variants/shogi/pieces/CMakeLists.txt create mode 100644 src/variants/shogi/pieces/pawn.cpp rename src/variants/shogi/{ => pieces}/pawn.h (68%) create mode 100644 src/variants/shogi/type.cpp rename src/variants/shogi/{dragonking.h => type.h} (72%) diff --git a/src/core/piece.cpp b/src/core/piece.cpp index 84a4841..cd6f8ff 100644 --- a/src/core/piece.cpp +++ b/src/core/piece.cpp @@ -10,13 +10,14 @@ #include "piece.h" -Piece::Piece(const IColor* color, const IType* type) +Piece::Piece(const IColor* color, IType* type) : m_type(type) , m_color(color) { } const IColor* Piece::color() const { return m_color; } const IType* Piece::type() const { return m_type; } +IType* Piece::type() { return m_type; } void Piece::setType(const IType* type) { m_type = type; } bool Piece::operator==(const Piece& piece) const { diff --git a/src/core/piece.h b/src/core/piece.h index e7f29e1..67c9f9f 100644 --- a/src/core/piece.h +++ b/src/core/piece.h @@ -18,14 +18,14 @@ class IType; class IColor; class TAGUA_EXPORT Piece : public TaguaObject { - const IType* m_type; + IType* m_type; const IColor* m_color; public: - Piece(const IColor* color = 0, const IType* type = 0); - virtual ~Piece() {}; + Piece(const IColor* color = 0, IType* type = 0); const IColor* color() const; const IType* type() const; + IType* type(); void setType(const IType* type); bool operator==(const Piece& other) const; diff --git a/src/variants/shogi/CMakeLists.txt b/src/variants/shogi/CMakeLists.txt index d14f122..8a37583 100644 --- a/src/variants/shogi/CMakeLists.txt +++ b/src/variants/shogi/CMakeLists.txt @@ -1,23 +1,15 @@ +add_subdirectory(faces) +add_subdirectory(pieces) + set(taguashogi_SRCS shogi.cpp - king.cpp - gold.cpp - silver.cpp - knight.cpp - lance.cpp - pawn.cpp - rook.cpp - bishop.cpp - dragonking.cpp - dragonhorse.cpp - behaviour.cpp colors.cpp moveserializer.cpp - piece.cpp # san.cpp state.cpp + type.cpp validator.cpp ) @@ -28,6 +20,8 @@ kde4_add_plugin(taguashogi ${taguashogi_SRCS}) target_link_libraries(taguashogi taguacore taguachesslib + shogifaces + shogipieces ${KDE4_KDECORE_LIBS} ) diff --git a/src/variants/shogi/behaviour.cpp b/src/variants/shogi/behaviour.cpp index 2f4bf17..dd53970 100644 --- a/src/variants/shogi/behaviour.cpp +++ b/src/variants/shogi/behaviour.cpp @@ -10,11 +10,12 @@ #include "behaviour.h" #include +#include #include #include #include -#include "piece.h" +#include "type.h" namespace Shogi { @@ -24,7 +25,7 @@ Behaviour::Behaviour(const IBehaviour* behaviour) void Behaviour::captureOn(IState* state, const Point& square) const { Piece* captured = dynamic_cast(state->board()->get(square)); if (captured != NULL && *captured != Piece()) { - captured->setPromoted(false); + dynamic_cast(captured->type())->setPromoted(false); state->pools()->pool(opponent(captured->color()))->insert(-1, *captured); } m_behaviour->captureOn(state, square); diff --git a/src/variants/shogi/faces/CMakeLists.txt b/src/variants/shogi/faces/CMakeLists.txt new file mode 100644 index 0000000..3ad782a --- /dev/null +++ b/src/variants/shogi/faces/CMakeLists.txt @@ -0,0 +1,21 @@ +set(shogifaces_SRC + pawn.cpp + king.cpp + gold.cpp + silver.cpp + knight.cpp + lance.cpp + rook.cpp + bishop.cpp + dragonking.cpp + dragonhorse.cpp +) + +include_directories(${CMAKE_SOURCE_DIR}/src/) + +ADD_LIBRARY(shogifaces STATIC ${shogifaces_SRC}) + +target_link_libraries(shogifaces + taguacore +# ${KDE4_KDECORE_LIBS} +) diff --git a/src/variants/shogi/bishop.cpp b/src/variants/shogi/faces/bishop.cpp similarity index 93% rename from src/variants/shogi/bishop.cpp rename to src/variants/shogi/faces/bishop.cpp index d16b786..418258e 100644 --- a/src/variants/shogi/bishop.cpp +++ b/src/variants/shogi/faces/bishop.cpp @@ -15,6 +15,7 @@ #include namespace Shogi { +namespace Faces { Bishop::Bishop() { } @@ -26,7 +27,7 @@ bool Bishop::canMove(const Piece& piece, const Piece& target, return path.diagonal() && path.clear() && target.color() != piece.color(); } -int Bishop::index() const { return 35; } +int Bishop::index() const { return 100; } Bishop* Bishop::self() { static Bishop s_instance; @@ -34,3 +35,4 @@ Bishop* Bishop::self() { } } +} diff --git a/src/variants/shogi/bishop.h b/src/variants/shogi/faces/bishop.h similarity index 86% rename from src/variants/shogi/bishop.h rename to src/variants/shogi/faces/bishop.h index 2a7de19..8b972a9 100644 --- a/src/variants/shogi/bishop.h +++ b/src/variants/shogi/faces/bishop.h @@ -8,13 +8,14 @@ (at your option) any later version. */ -#ifndef SHOGI__TYPES__BISHOP_H -#define SHOGI__TYPES__BISHOP_H +#ifndef SHOGI__FACES__BISHOP_H +#define SHOGI__FACES__BISHOP_H #include #include namespace Shogi { +namespace Faces { class TAGUA_EXPORT Bishop : public Component, public IType { Q_OBJECT @@ -28,5 +29,6 @@ public: }; } +} -#endif // SHOGI__TYPES__BISHOP_H +#endif // SHOGI__FACES__BISHOP_H diff --git a/src/variants/shogi/dragonhorse.cpp b/src/variants/shogi/faces/dragonhorse.cpp similarity index 93% rename from src/variants/shogi/dragonhorse.cpp rename to src/variants/shogi/faces/dragonhorse.cpp index 6c04632..5143be4 100644 --- a/src/variants/shogi/dragonhorse.cpp +++ b/src/variants/shogi/faces/dragonhorse.cpp @@ -15,6 +15,7 @@ #include namespace Shogi { +namespace Faces { DragonHorse::DragonHorse() { } @@ -26,7 +27,7 @@ bool DragonHorse::canMove(const Piece& piece, const Piece& target, return path.diagonal() && path.clear() && target.color() != piece.color(); } -int DragonHorse::index() const { return 35; } +int DragonHorse::index() const { return 200; } DragonHorse* DragonHorse::self() { static DragonHorse s_instance; @@ -34,3 +35,4 @@ DragonHorse* DragonHorse::self() { } } +} diff --git a/src/variants/shogi/dragonhorse.h b/src/variants/shogi/faces/dragonhorse.h similarity index 85% rename from src/variants/shogi/dragonhorse.h rename to src/variants/shogi/faces/dragonhorse.h index 5e8c9b2..f663c94 100644 --- a/src/variants/shogi/dragonhorse.h +++ b/src/variants/shogi/faces/dragonhorse.h @@ -8,13 +8,14 @@ (at your option) any later version. */ -#ifndef SHOGI__TYPES__DRAGONHORSE_H -#define SHOGI__TYPES__DRAGONHORSE_H +#ifndef SHOGI__FACES__DRAGONHORSE_H +#define SHOGI__FACES__DRAGONHORSE_H #include #include namespace Shogi { +namespace Faces { class TAGUA_EXPORT DragonHorse : public Component, public IType { Q_OBJECT @@ -28,5 +29,6 @@ public: }; } +} -#endif // SHOGI__TYPES__DRAGONHORSE_H +#endif // SHOGI__FACES__DRAGONHORSE_H diff --git a/src/variants/shogi/dragonking.cpp b/src/variants/shogi/faces/dragonking.cpp similarity index 93% rename from src/variants/shogi/dragonking.cpp rename to src/variants/shogi/faces/dragonking.cpp index 473faea..dc3f9c7 100644 --- a/src/variants/shogi/dragonking.cpp +++ b/src/variants/shogi/faces/dragonking.cpp @@ -15,6 +15,7 @@ #include namespace Shogi { +namespace Faces { DragonKing::DragonKing() { } @@ -26,7 +27,7 @@ bool DragonKing::canMove(const Piece& piece, const Piece& target, return path.parallel() && path.clear() && target.color() != piece.color(); } -int DragonKing::index() const { return 50; } +int DragonKing::index() const { return 300; } DragonKing* DragonKing::self() { static DragonKing s_instance; @@ -34,3 +35,4 @@ DragonKing* DragonKing::self() { } } +} diff --git a/src/variants/shogi/dragonking.h b/src/variants/shogi/faces/dragonking.h similarity index 85% copy from src/variants/shogi/dragonking.h copy to src/variants/shogi/faces/dragonking.h index 21cff66..f383998 100644 --- a/src/variants/shogi/dragonking.h +++ b/src/variants/shogi/faces/dragonking.h @@ -8,13 +8,14 @@ (at your option) any later version. */ -#ifndef SHOGI__TYPES__DRAGONKING_H -#define SHOGI__TYPES__DRAGONKING_H +#ifndef SHOGI__FACES__DRAGONKING_H +#define SHOGI__FACES__DRAGONKING_H #include #include namespace Shogi { +namespace Faces { class TAGUA_EXPORT DragonKing : public Component, public IType { Q_OBJECT @@ -28,5 +29,6 @@ public: }; } +} -#endif // SHOGI__TYPES__DRAGONKING_H +#endif // SHOGI__FACES__DRAGONKING_H diff --git a/src/variants/shogi/gold.cpp b/src/variants/shogi/faces/gold.cpp similarity index 94% rename from src/variants/shogi/gold.cpp rename to src/variants/shogi/faces/gold.cpp index a3414cf..8dda8ef 100644 --- a/src/variants/shogi/gold.cpp +++ b/src/variants/shogi/faces/gold.cpp @@ -14,6 +14,7 @@ #include namespace Shogi { +namespace Faces { Gold::Gold() { } @@ -28,7 +29,7 @@ bool Gold::canMove(const Piece& piece, const Piece&, || (move.delta().y == behaviour->direction(piece.color()).y && abs(move.delta().x) <= 1)); } -int Gold::index() const { return 10000; } +int Gold::index() const { return 60; } Gold* Gold::self() { static Gold s_instance; @@ -36,3 +37,4 @@ Gold* Gold::self() { } } +} diff --git a/src/variants/shogi/gold.h b/src/variants/shogi/faces/gold.h similarity index 87% rename from src/variants/shogi/gold.h rename to src/variants/shogi/faces/gold.h index 59feb8d..8ee7780 100644 --- a/src/variants/shogi/gold.h +++ b/src/variants/shogi/faces/gold.h @@ -8,13 +8,14 @@ (at your option) any later version. */ -#ifndef SHOGI__TYPES__GOLD_H -#define SHOGI__TYPES__GOLD_H +#ifndef SHOGI__FACES__GOLD_H +#define SHOGI__FACES__GOLD_H #include #include namespace Shogi { +namespace Faces { class ICastlingRules; @@ -30,5 +31,6 @@ public: }; } +} -#endif // SHOGI__TYPES__GOLD_H +#endif // SHOGI__FACES__GOLD_H diff --git a/src/variants/shogi/king.cpp b/src/variants/shogi/faces/king.cpp similarity index 97% rename from src/variants/shogi/king.cpp rename to src/variants/shogi/faces/king.cpp index 8a6da22..6b89ef6 100644 --- a/src/variants/shogi/king.cpp +++ b/src/variants/shogi/faces/king.cpp @@ -12,6 +12,7 @@ #include namespace Shogi { +namespace Faces { King::King() { } @@ -31,3 +32,4 @@ King* King::self() { } } +} diff --git a/src/variants/shogi/king.h b/src/variants/shogi/faces/king.h similarity index 87% rename from src/variants/shogi/king.h rename to src/variants/shogi/faces/king.h index 9059f9d..e226d56 100644 --- a/src/variants/shogi/king.h +++ b/src/variants/shogi/faces/king.h @@ -8,13 +8,14 @@ (at your option) any later version. */ -#ifndef SHOGI__TYPES__KING_H -#define SHOGI__TYPES__KING_H +#ifndef SHOGI__FACES__KING_H +#define SHOGI__FACES__KING_H #include #include namespace Shogi { +namespace Faces { class TAGUA_EXPORT King : public Component, public IType { Q_OBJECT @@ -28,5 +29,6 @@ public: }; } +} -#endif // SHOGI__TYPES__KING_H +#endif // SHOGI__FACES__KING_H diff --git a/src/variants/shogi/knight.cpp b/src/variants/shogi/faces/knight.cpp similarity index 98% rename from src/variants/shogi/knight.cpp rename to src/variants/shogi/faces/knight.cpp index 3a4a6b8..4942ff1 100644 --- a/src/variants/shogi/knight.cpp +++ b/src/variants/shogi/faces/knight.cpp @@ -16,6 +16,7 @@ #include namespace Shogi { +namespace Faces { Knight::Knight() { } @@ -37,3 +38,4 @@ Knight* Knight::self() { } } +} diff --git a/src/variants/shogi/knight.h b/src/variants/shogi/faces/knight.h similarity index 86% rename from src/variants/shogi/knight.h rename to src/variants/shogi/faces/knight.h index 3167d08..32fc44e 100644 --- a/src/variants/shogi/knight.h +++ b/src/variants/shogi/faces/knight.h @@ -8,13 +8,14 @@ (at your option) any later version. */ -#ifndef SHOGI__TYPES__KNIGHT_H -#define SHOGI__TYPES__KNIGHT_H +#ifndef SHOGI__FACES__KNIGHT_H +#define SHOGI__FACES__KNIGHT_H #include #include namespace Shogi { +namespace Faces { class TAGUA_EXPORT Knight : public Component, public IType { Q_OBJECT @@ -28,5 +29,6 @@ public: }; } +} -#endif // SHOGI__TYPES__KNIGHT_H +#endif // SHOGI__FACES__KNIGHT_H diff --git a/src/variants/shogi/lance.cpp b/src/variants/shogi/faces/lance.cpp similarity index 94% rename from src/variants/shogi/lance.cpp rename to src/variants/shogi/faces/lance.cpp index 7a99430..c543698 100644 --- a/src/variants/shogi/lance.cpp +++ b/src/variants/shogi/faces/lance.cpp @@ -16,6 +16,7 @@ #include namespace Shogi { +namespace Faces { Lance::Lance() { } @@ -31,7 +32,7 @@ bool Lance::canMove(const Piece& piece, const Piece&, (move.delta().y * behaviour->direction(piece.color()).y > 0); } -int Lance::index() const { return 10000; } +int Lance::index() const { return 40; } Lance* Lance::self() { static Lance s_instance; @@ -39,3 +40,4 @@ Lance* Lance::self() { } } +} diff --git a/src/variants/shogi/lance.h b/src/variants/shogi/faces/lance.h similarity index 87% rename from src/variants/shogi/lance.h rename to src/variants/shogi/faces/lance.h index 9f9d249..444b044 100644 --- a/src/variants/shogi/lance.h +++ b/src/variants/shogi/faces/lance.h @@ -8,13 +8,14 @@ (at your option) any later version. */ -#ifndef SHOGI__TYPES__LANCE_H -#define SHOGI__TYPES__LANCE_H +#ifndef SHOGI__FACES__LANCE_H +#define SHOGI__FACES__LANCE_H #include #include namespace Shogi { +namespace Faces { class ICastlingRules; @@ -30,5 +31,6 @@ public: }; } +} -#endif // SHOGI__TYPES__LANCE_H +#endif // SHOGI__FACES__LANCE_H diff --git a/src/variants/shogi/pawn.cpp b/src/variants/shogi/faces/pawn.cpp similarity index 98% rename from src/variants/shogi/pawn.cpp rename to src/variants/shogi/faces/pawn.cpp index 5c3776b..55e9f42 100644 --- a/src/variants/shogi/pawn.cpp +++ b/src/variants/shogi/faces/pawn.cpp @@ -17,6 +17,7 @@ #include namespace Shogi { +namespace Faces { Pawn::Pawn() { } @@ -38,3 +39,4 @@ Pawn* Pawn::self() { } } +} diff --git a/src/variants/shogi/pawn.h b/src/variants/shogi/faces/pawn.h similarity index 87% copy from src/variants/shogi/pawn.h copy to src/variants/shogi/faces/pawn.h index 9304103..4ecc796 100644 --- a/src/variants/shogi/pawn.h +++ b/src/variants/shogi/faces/pawn.h @@ -8,13 +8,14 @@ (at your option) any later version. */ -#ifndef SHOGI__TYPES__PAWN_H -#define SHOGI__TYPES__PAWN_H +#ifndef SHOGI__FACES__PAWN_H +#define SHOGI__FACES__PAWN_H #include #include namespace Shogi { +namespace Faces { class TAGUA_EXPORT Pawn : public Component, public IType { Q_OBJECT @@ -28,5 +29,6 @@ public: }; } +} -#endif // SHOGI__TYPES__PAWN_H +#endif // SHOGI__FACES__PAWN_H diff --git a/src/variants/shogi/rook.cpp b/src/variants/shogi/faces/rook.cpp similarity index 93% rename from src/variants/shogi/rook.cpp rename to src/variants/shogi/faces/rook.cpp index c0ec689..c0e211e 100644 --- a/src/variants/shogi/rook.cpp +++ b/src/variants/shogi/faces/rook.cpp @@ -15,6 +15,7 @@ #include namespace Shogi { +namespace Faces { Rook::Rook() { } @@ -26,7 +27,7 @@ bool Rook::canMove(const Piece& piece, const Piece& target, return path.parallel() && path.clear() && target.color() != piece.color(); } -int Rook::index() const { return 50; } +int Rook::index() const { return 150; } Rook* Rook::self() { static Rook s_instance; @@ -34,3 +35,4 @@ Rook* Rook::self() { } } +} diff --git a/src/variants/shogi/rook.h b/src/variants/shogi/faces/rook.h similarity index 87% rename from src/variants/shogi/rook.h rename to src/variants/shogi/faces/rook.h index 1d978f3..7a0f3ca 100644 --- a/src/variants/shogi/rook.h +++ b/src/variants/shogi/faces/rook.h @@ -8,13 +8,14 @@ (at your option) any later version. */ -#ifndef SHOGI__TYPES__ROOK_H -#define SHOGI__TYPES__ROOK_H +#ifndef SHOGI__FACES__ROOK_H +#define SHOGI__FACES__ROOK_H #include #include namespace Shogi { +namespace Faces { class TAGUA_EXPORT Rook : public Component, public IType { Q_OBJECT @@ -28,5 +29,6 @@ public: }; } +} -#endif // SHOGI__TYPES__ROOK_H +#endif // SHOGI__FACES__ROOK_H diff --git a/src/variants/shogi/silver.cpp b/src/variants/shogi/faces/silver.cpp similarity index 94% rename from src/variants/shogi/silver.cpp rename to src/variants/shogi/faces/silver.cpp index 8b3a99b..d12d500 100644 --- a/src/variants/shogi/silver.cpp +++ b/src/variants/shogi/faces/silver.cpp @@ -14,6 +14,7 @@ #include namespace Shogi { +namespace Faces { Silver::Silver() { } @@ -27,7 +28,7 @@ bool Silver::canMove(const Piece& piece, const Piece&, || (move.delta().y == behaviour->direction(piece.color()).y && abs(move.delta().x) <= 1); } -int Silver::index() const { return 10000; } +int Silver::index() const { return 50; } Silver* Silver::self() { static Silver s_instance; @@ -35,3 +36,4 @@ Silver* Silver::self() { } } +} diff --git a/src/variants/shogi/silver.h b/src/variants/shogi/faces/silver.h similarity index 87% rename from src/variants/shogi/silver.h rename to src/variants/shogi/faces/silver.h index 3d3dd3a..8cda19e 100644 --- a/src/variants/shogi/silver.h +++ b/src/variants/shogi/faces/silver.h @@ -8,13 +8,14 @@ (at your option) any later version. */ -#ifndef SHOGI__TYPES__SILVER_H -#define SHOGI__TYPES__SILVER_H +#ifndef SHOGI__FACES__SILVER_H +#define SHOGI__FACES__SILVER_H #include #include namespace Shogi { +namespace Faces { class ICastlingRules; @@ -30,5 +31,6 @@ public: }; } +} -#endif // SHOGI__TYPES__SILVER_H +#endif // SHOGI__FACES__SILVER_H diff --git a/src/variants/shogi/piece.cpp b/src/variants/shogi/piece.cpp deleted file mode 100644 index 408d8b1..0000000 --- a/src/variants/shogi/piece.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "piece.h" - -namespace Shogi { - -Piece::Piece(const IColor* color, const IType* type, - const IType* promotion) - : ::Piece(color) - , m_unpromoted_type(type) - , m_promoted_type(promotion) -{ - setPromoted(false); -} - -void Piece::setPromoted(bool promoted) -{ - if (promoted) { - setType(m_promoted_type); - set("promoted", true); - } else { - setType(m_unpromoted_type); - set("promoted", false); - } -} - -bool Piece::canPromote() -{ - return type() == m_unpromoted_type - && m_promoted_type != 0; -} - -} // namespace Shogi diff --git a/src/variants/shogi/piece.h b/src/variants/shogi/piece.h deleted file mode 100644 index ddfc71c..0000000 --- a/src/variants/shogi/piece.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef SHOGI__PIECE_H -#define SHOGI__PIECE_H - -#include - -class IType; -class IColor; - -namespace Shogi { - -class TAGUA_EXPORT Piece : public ::Piece { - const IType* m_unpromoted_type; - const IType* m_promoted_type; -public: - Piece(const IColor* color = 0, const IType* type = 0, - const IType* promotion = 0); - - void setPromoted(bool promoted); - bool canPromote(); - -#if 0 - bool operator==(const Piece& other) const; - bool operator!=(const Piece& other) const; -#endif -}; - -} // namespace Shogi - -#endif // SHOGI__PIECE_H diff --git a/src/variants/shogi/pieces/CMakeLists.txt b/src/variants/shogi/pieces/CMakeLists.txt new file mode 100644 index 0000000..951d951 --- /dev/null +++ b/src/variants/shogi/pieces/CMakeLists.txt @@ -0,0 +1,18 @@ +set(shogipieces_SRC + pawn.cpp +# king.cpp +# gold.cpp +# silver.cpp +# knight.cpp +# lance.cpp +# rook.cpp +# bishop.cpp +) + +include_directories(${CMAKE_SOURCE_DIR}/src/) + +ADD_LIBRARY(shogipieces STATIC ${shogipieces_SRC}) + +target_link_libraries(shogipieces + taguacore +) diff --git a/src/variants/shogi/pieces/pawn.cpp b/src/variants/shogi/pieces/pawn.cpp new file mode 100644 index 0000000..6c491e6 --- /dev/null +++ b/src/variants/shogi/pieces/pawn.cpp @@ -0,0 +1,14 @@ +#include "pawn.h" + +namespace Shogi { +namespace Types { + +Pawn::Pawn() { } + +Pawn* Pawn::self() { + static Pawn s_instance; + return &s_instance; +} + +} +} diff --git a/src/variants/shogi/pawn.h b/src/variants/shogi/pieces/pawn.h similarity index 68% rename from src/variants/shogi/pawn.h rename to src/variants/shogi/pieces/pawn.h index 9304103..012b7b0 100644 --- a/src/variants/shogi/pawn.h +++ b/src/variants/shogi/pieces/pawn.h @@ -12,21 +12,19 @@ #define SHOGI__TYPES__PAWN_H #include -#include +#include "../type.h" namespace Shogi { +namespace Types { -class TAGUA_EXPORT Pawn : public Component, public IType { +class TAGUA_EXPORT Pawn : public Type { Q_OBJECT Pawn(); public: - virtual QString name() const; - virtual bool canMove(const Piece& piece, const Piece& target, - Move& move, const IState* state) const; - virtual int index() const; static Pawn* self(); }; } +} #endif // SHOGI__TYPES__PAWN_H diff --git a/src/variants/shogi/shogi.cpp b/src/variants/shogi/shogi.cpp index 0097040..457e500 100644 --- a/src/variants/shogi/shogi.cpp +++ b/src/variants/shogi/shogi.cpp @@ -27,14 +27,18 @@ taguashogi_initrepo(IVariantLoader* loader) { repo->addComponent("player/0", dynamic_cast(COLORS[0])); repo->addComponent("player/1", dynamic_cast(COLORS[1])); - repo->addComponent("type/king", King::self()); - repo->addComponent("type/gold", Gold::self()); - repo->addComponent("type/silver", Silver::self()); - repo->addComponent("type/knight", Knight::self()); - repo->addComponent("type/lance", Lance::self()); - repo->addComponent("type/rook", Rook::self()); - repo->addComponent("type/bishop", Bishop::self()); - repo->addComponent("type/pawn", Pawn::self()); +#if 0 + repo->addComponent("type/king", Types::King::self()); + repo->addComponent("type/gold", Types::Gold::self()); + repo->addComponent("type/silver", Types::Silver::self()); + repo->addComponent("type/knight", Types::Knight::self()); + repo->addComponent("type/lance", Types::Lance::self()); + repo->addComponent("type/rook", Types::Rook::self()); + repo->addComponent("type/bishop", Types::Bishop::self()); +#else +#warning missing piece types +#endif + repo->addComponent("type/pawn", Types::Pawn::self()); #if 0 // create crazyhouse behaviour diff --git a/src/variants/shogi/state.cpp b/src/variants/shogi/state.cpp index 39e102d..535db2e 100644 --- a/src/variants/shogi/state.cpp +++ b/src/variants/shogi/state.cpp @@ -16,7 +16,6 @@ #include #include "colors.h" -#include "piece.h" #include "types.h" namespace Shogi { diff --git a/src/variants/shogi/state.h b/src/variants/shogi/state.h index 10eeadb..8a46912 100644 --- a/src/variants/shogi/state.h +++ b/src/variants/shogi/state.h @@ -14,6 +14,7 @@ #include #include #include +#include #include namespace Shogi { diff --git a/src/variants/shogi/type.cpp b/src/variants/shogi/type.cpp new file mode 100644 index 0000000..dbb3a49 --- /dev/null +++ b/src/variants/shogi/type.cpp @@ -0,0 +1,28 @@ +#include + +#include "type.h" + +namespace Shogi { + +QString Type::name() const { + return m_unpromoted_type->name(); +} + +bool Type::canMove(const Piece& piece, const Piece&, + Move& move, const IState* state) const { + if (promoted) + return m_promoted_type->canMove(piece, Piece(), move, state); + else + return m_unpromoted_type->canMove(piece, Piece(), move, state); +} + +void Type::setPromoted(bool promoted_) +{ + promoted = promoted_; +} + +int Type::index() const { + return m_unpromoted_type->index(); +} + +} diff --git a/src/variants/shogi/dragonking.h b/src/variants/shogi/type.h similarity index 72% rename from src/variants/shogi/dragonking.h rename to src/variants/shogi/type.h index 21cff66..42822d3 100644 --- a/src/variants/shogi/dragonking.h +++ b/src/variants/shogi/type.h @@ -8,25 +8,28 @@ (at your option) any later version. */ -#ifndef SHOGI__TYPES__DRAGONKING_H -#define SHOGI__TYPES__DRAGONKING_H +#ifndef SHOGI__TYPE_H +#define SHOGI__TYPE_H #include #include namespace Shogi { -class TAGUA_EXPORT DragonKing : public Component, public IType { +class TAGUA_EXPORT Type : public Component, public IType { Q_OBJECT - DragonKing(); + bool promoted; +protected: + const IType* m_unpromoted_type; + const IType* m_promoted_type; public: virtual QString name() const; virtual bool canMove(const Piece& piece, const Piece& target, Move& move, const IState* state) const; virtual int index() const; - static DragonKing* self(); + void setPromoted(bool promoted); }; } -#endif // SHOGI__TYPES__DRAGONKING_H +#endif // SHOGI__TYPE_H diff --git a/src/variants/shogi/types.h b/src/variants/shogi/types.h index e33795a..72f7cae 100644 --- a/src/variants/shogi/types.h +++ b/src/variants/shogi/types.h @@ -12,15 +12,13 @@ #define SHOGI__TYPES_H // include all shogi types -#include "king.h" -#include "gold.h" -#include "silver.h" -#include "knight.h" -#include "lance.h" -#include "rook.h" -#include "bishop.h" -#include "pawn.h" -#include "dragonking.h" -#include "dragonhorse.h" +//#include "king.h" +//#include "gold.h" +//#include "silver.h" +//#include "knight.h" +//#include "lance.h" +//#include "rook.h" +//#include "bishop.h" +#include "pieces/pawn.h" #endif // SHOGI__TYPES_H diff --git a/src/variants/shogi/validator.cpp b/src/variants/shogi/validator.cpp index 084e2b9..902929a 100644 --- a/src/variants/shogi/validator.cpp +++ b/src/variants/shogi/validator.cpp @@ -9,7 +9,6 @@ #include #include "colors.h" -#include "piece.h" #include "types.h" namespace Shogi { -- 2.11.4.GIT