From 2a1fa3a9a15461bf73f1875efa4153b373998999 Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Mon, 7 Apr 2008 02:01:00 +0200 Subject: [PATCH] refresh d7e71a93da39c621828977f6616ccc46c4b52116 --- debian/control | 25 ------------------------ src/core/behaviour.h | 6 ++++-- src/core/component.h | 8 ++++++++ src/core/delegators/behaviour.h | 5 ++--- src/variants/CMakeLists.txt | 5 ----- src/variants/chess/behaviour.cpp | 8 ++------ src/variants/chess/behaviour.h | 5 ++--- src/variants/crazyhouse/behaviour.h | 1 + src/variants/minishogi/CMakeLists.txt | 1 - src/variants/minishogi/behaviour.cpp | 3 +-- src/variants/minishogi/behaviour.h | 32 ++++++++++++++++++++++++++++--- src/variants/minishogi/minishogi.cpp | 23 ++++++++-------------- src/variants/shogi/CMakeLists.txt | 12 +----------- src/variants/shogi/behaviour.cpp | 25 ++++++++++++------------ src/variants/shogi/behaviour.h | 17 +++++++--------- src/variants/shogi/delegators/behaviour.h | 19 ++++++++++++++++++ src/variants/shogi/shogi.cpp | 14 +++++++------- src/variants/shogi/types/bishop.cpp | 18 +++++++++++++---- 18 files changed, 118 insertions(+), 109 deletions(-) diff --git a/debian/control b/debian/control index ed01cf4..5217d72 100644 --- a/debian/control +++ b/debian/control @@ -43,22 +43,6 @@ Provides: tagua-variant Description: Chess support for the tagua board-game frontend This package allows to play chess from tagua. -Package: tagua-variant-crazyhouse -Architecture: any -Depends: tagua, tagua-variant-chess -Provides: tagua-variant -Description: Crazyhouse support for the tagua board-game frontend - This package allows to play crazyhouse, a chess variant with drops, - from tagua. - -Package: tagua-variant-chess5x5 -Architecture: any -Depends: tagua, tagua-variant-chess -Provides: tagua-variant -Description: Chess 5x5 support for the tagua board-game frontend - This package allows to play "chess 5x5", a chess variant on a 5x5 - board, from tagua. - Package: tagua-variant-shogi Architecture: any Depends: tagua, tagua-variant-chess, tagua-variant-crazyhouse @@ -76,12 +60,3 @@ Provides: tagua-variant Description: MiniShogi support for the tagua board-game frontend This package allows to play MiniShogi, a variant on a 5x5 board of the japanese Shogi chess-like game, from tagua. - -Package: tagua-variant-entropy -Architecture: any -Depends: tagua, tagua-variant-chess -Provides: tagua-variant -Description: Randomless-Entropy support for the tagua board-game frontend - This package allows to play Randomless-Entropy, a variant of Entropy - where Chaos does not randomly draws the next stone to place, but can - choose from all stones in the pool, from tagua. diff --git a/src/core/behaviour.h b/src/core/behaviour.h index 07cb53b..77ad941 100644 --- a/src/core/behaviour.h +++ b/src/core/behaviour.h @@ -10,6 +10,7 @@ #ifndef CORE__BEHAVIOUR_H #define CORE__BEHAVIOUR_H +#include "component.h" #include "export.h" #include "point.h" @@ -20,11 +21,12 @@ class Move; /** * @brief Encapsulates general rules on piece movement. */ -class TAGUA_EXPORT IBehaviour { +class TAGUA_EXPORT IBehaviour: public Component { +Q_OBJECT public: virtual ~IBehaviour(); - virtual IBehaviour* clone() const = 0; + //virtual IBehaviour* clone() const = 0; /** * Perform a capture on a given square. In variants with drops, this diff --git a/src/core/component.h b/src/core/component.h index bf022a0..c1c6ec7 100644 --- a/src/core/component.h +++ b/src/core/component.h @@ -14,6 +14,8 @@ #include "component_fwd.h" #include "export.h" #include +#include +#include /** * @brief A Component is a reusable unit in the description of a Tagua variant. @@ -24,4 +26,10 @@ public: Component(); }; +static inline void dump_component_methods(Component* c) { + const QMetaObject* mo = c->metaObject(); + for (int i=0; i < mo->methodCount(); i++) + kDebug() << " ** " << mo->method(i).signature() << "->" << mo->method(i).typeName(); +} + #endif // CORE__COMPONENT_H diff --git a/src/core/delegators/behaviour.h b/src/core/delegators/behaviour.h index 5df7a3e..7d43ecc 100644 --- a/src/core/delegators/behaviour.h +++ b/src/core/delegators/behaviour.h @@ -20,7 +20,8 @@ class Behaviour : virtual public IBehaviour { protected: IBehaviour* m_dgate_behaviour; public: - Behaviour(IBehaviour* delegate) : m_dgate_behaviour(delegate) { + Behaviour(IBehaviour* delegate): m_dgate_behaviour(delegate) { + Q_ASSERT(delegate); m_dgate_behaviour->setDelegator(this); kDebug() << this << "m_dgate_behaviour=" << m_dgate_behaviour; } @@ -51,5 +52,3 @@ public: } #endif // DELEGATORS__BEHAVIOUR_H - - diff --git a/src/variants/CMakeLists.txt b/src/variants/CMakeLists.txt index 3c721df..8cd162b 100644 --- a/src/variants/CMakeLists.txt +++ b/src/variants/CMakeLists.txt @@ -1,8 +1,3 @@ add_subdirectory(chess) -add_subdirectory(chess5x5) -add_subdirectory(crazyhouse) - add_subdirectory(shogi) add_subdirectory(minishogi) - -add_subdirectory(randomless-entropy) diff --git a/src/variants/chess/behaviour.cpp b/src/variants/chess/behaviour.cpp index 214e1f6..8c4ea5b 100644 --- a/src/variants/chess/behaviour.cpp +++ b/src/variants/chess/behaviour.cpp @@ -17,11 +17,9 @@ namespace Chess { Behaviour::Behaviour() -: IBehaviour() -, Component() { } +: IBehaviour() { } Behaviour::Behaviour(const Behaviour& other) -: IBehaviour() -, Component() { } // FIXME ? +: IBehaviour() { } IBehaviour* Behaviour::clone() const { return new Behaviour(*this); @@ -60,5 +58,3 @@ Point Behaviour::direction(const IColor* player) const { } } // namespace Chess - - diff --git a/src/variants/chess/behaviour.h b/src/variants/chess/behaviour.h index 8839379..855412d 100644 --- a/src/variants/chess/behaviour.h +++ b/src/variants/chess/behaviour.h @@ -15,12 +15,11 @@ namespace Chess { -class Behaviour : public Component, virtual public IBehaviour { +class Behaviour : public IBehaviour { Q_OBJECT public: Behaviour(); Behaviour(const Behaviour& other); - virtual IBehaviour* clone() const; virtual void captureOn(IState* state, const Point& square) const; virtual void move(IState* state, const Move& m) const; virtual void advanceTurn(IState* state) const; @@ -29,7 +28,7 @@ public: virtual Point direction(const IColor* player) const; virtual void setDelegator(IBehaviour* behaviour) { } public Q_SLOTS: - //virtual Component* clone() const; + virtual IBehaviour* clone() const; }; } // namespace Chess diff --git a/src/variants/crazyhouse/behaviour.h b/src/variants/crazyhouse/behaviour.h index 0983863..e4f095e 100644 --- a/src/variants/crazyhouse/behaviour.h +++ b/src/variants/crazyhouse/behaviour.h @@ -15,6 +15,7 @@ namespace Crazyhouse { class Behaviour : public Delegators::Behaviour { +Q_OBJECT public: Behaviour(IBehaviour* behaviour); diff --git a/src/variants/minishogi/CMakeLists.txt b/src/variants/minishogi/CMakeLists.txt index f137b77..30c7b4b 100644 --- a/src/variants/minishogi/CMakeLists.txt +++ b/src/variants/minishogi/CMakeLists.txt @@ -10,7 +10,6 @@ kde4_add_plugin(taguaminishogi ${taguaminishogi_SRCS}) target_link_libraries(taguaminishogi taguacore - taguashogilib ${KDE4_KDECORE_LIBS} ) diff --git a/src/variants/minishogi/behaviour.cpp b/src/variants/minishogi/behaviour.cpp index a60058d..1a3d88f 100644 --- a/src/variants/minishogi/behaviour.cpp +++ b/src/variants/minishogi/behaviour.cpp @@ -3,7 +3,6 @@ namespace MiniShogi { Behaviour::Behaviour(IBehaviour* behaviour) - : Delegators::Behaviour(behaviour) - , Delegators::ShogiBehaviour(behaviour) { } + : Delegators::Behaviour(behaviour) { } } // namespace MiniShogi diff --git a/src/variants/minishogi/behaviour.h b/src/variants/minishogi/behaviour.h index 9c539fe..cdcaf8b 100644 --- a/src/variants/minishogi/behaviour.h +++ b/src/variants/minishogi/behaviour.h @@ -10,17 +10,43 @@ #ifndef MINISHOGI__BEHAVIOUR_H #define MINISHOGI__BEHAVIOUR_H -#include "../shogi/delegators/behaviour.h" +#include +#include class Move; namespace MiniShogi { -class Behaviour : public Delegators::ShogiBehaviour { +class TAGUA_EXPORT Behaviour : public Delegators::Behaviour { Q_OBJECT + Behaviour* m_delegator; public: Behaviour(IBehaviour* behaviour); - virtual unsigned promotionZoneWidth() const { return 1; } + +public Q_SLOTS: // delegated + void setPromotionManager(PromotionManager* pm) { + Q_ASSERT(QMetaObject::invokeMethod(m_dgate_behaviour, "setPromotionManager", + Q_ARG(PromotionManager*, pm))); + } + + const PromotionManager* promotionManager() const { + const PromotionManager* result; + Q_ASSERT(QMetaObject::invokeMethod(m_dgate_behaviour, "promotionManager", + Q_RETURN_ARG(const PromotionManager*, result))); + return result; + } + + bool mayPromote(const IState* state, const Move& move) const { + bool result; + Q_ASSERT(QMetaObject::invokeMethod(m_dgate_behaviour, "mayPromote", + Q_RETURN_ARG(bool, result), + Q_ARG(const IState*, state), + Q_ARG(const Move, move))); + return result; + } + +public Q_SLOTS: // overridden + unsigned promotionZoneWidth() const { return 1; } }; } // namespace MiniShogi diff --git a/src/variants/minishogi/minishogi.cpp b/src/variants/minishogi/minishogi.cpp index 265005b..d87b810 100644 --- a/src/variants/minishogi/minishogi.cpp +++ b/src/variants/minishogi/minishogi.cpp @@ -27,7 +27,6 @@ namespace MiniShogi { extern "C" KDE_EXPORT Repository* taguaminishogi_initrepo(IVariantLoader* loader) { - bool ok; Repository* repo = new Repository; Repository* shogi = loader->getRepository("shogi"); if (!shogi) @@ -43,25 +42,19 @@ taguaminishogi_initrepo(IVariantLoader* loader) { // base behaviour on shogi Component* shogi_behaviour_comp = shogi->getComponent("behaviour"); Q_ASSERT(shogi_behaviour_comp); - Component* behaviour_comp = NULL; - ok = QMetaObject::invokeMethod(shogi_behaviour_comp, "clone", - Q_RETURN_ARG(Component*, behaviour_comp), - Q_ARG(PromotionManager*, NULL)); - kDebug() << "cloning prototype behaviour" << ok; - Q_ASSERT(ok); - Q_ASSERT(behaviour_comp); - Shogi::Behaviour* behaviour_clone = requestInterface(behaviour_comp); + IBehaviour* behaviour_clone = NULL; + Q_ASSERT(QMetaObject::invokeMethod(shogi_behaviour_comp, "clone", + Q_RETURN_ARG(IBehaviour*, behaviour_clone), + Q_ARG(PromotionManager*, NULL))); Q_ASSERT(behaviour_clone); Behaviour* behaviour = new Behaviour(behaviour_clone); // create minishogi state factory Component* state_component = 0; - ok = QMetaObject::invokeMethod(shogi_state_comp, "clone", - Q_RETURN_ARG(Component*, state_component), - Q_ARG(const IBehaviour*, behaviour), - Q_ARG(Point, Point(5, 5))); - kDebug() << "cloning prototype state" << ok; - Q_ASSERT(ok); + Q_ASSERT(QMetaObject::invokeMethod(shogi_state_comp, "clone", + Q_RETURN_ARG(Component*, state_component), + Q_ARG(const IBehaviour*, behaviour), + Q_ARG(Point, Point(5, 5)))); Q_ASSERT(state_component); State* state = new State(requestInterface< ::DefaultState>(state_component)); diff --git a/src/variants/shogi/CMakeLists.txt b/src/variants/shogi/CMakeLists.txt index 2a6c30f..81842e9 100644 --- a/src/variants/shogi/CMakeLists.txt +++ b/src/variants/shogi/CMakeLists.txt @@ -1,13 +1,3 @@ -set(taguashogilib_SRCS - behaviour.cpp -) -kde4_add_library(taguashogilib SHARED ${taguashogilib_SRCS}) -target_link_libraries(taguashogilib - taguacore - ${KDE4_KDECORE_LIBS} -) -install(TARGETS taguashogilib DESTINATION ${LIB_INSTALL_DIR}) - set(taguashogi_SRCS shogi.cpp @@ -27,6 +17,7 @@ set(taguashogi_SRCS types/dragonking.cpp types/dragonhorse.cpp + behaviour.cpp colors.cpp moveserializer.cpp # san.cpp @@ -40,7 +31,6 @@ kde4_add_plugin(taguashogi ${taguashogi_SRCS}) target_link_libraries(taguashogi taguacore - taguashogilib ${KDE4_KDECORE_LIBS} ) diff --git a/src/variants/shogi/behaviour.cpp b/src/variants/shogi/behaviour.cpp index ec09775..ed4d1b4 100644 --- a/src/variants/shogi/behaviour.cpp +++ b/src/variants/shogi/behaviour.cpp @@ -27,7 +27,10 @@ Behaviour::Behaviour(IBehaviour* behaviour) , m_delegator(this) { } IBehaviour* Behaviour::clone() const { - Behaviour* b = new Behaviour(m_dgate_behaviour->clone()); + IBehaviour* dgate_clone; + Q_ASSERT(QMetaObject::invokeMethod(m_dgate_behaviour, "clone", + Q_RETURN_ARG(IBehaviour*, dgate_clone))); + Behaviour* b = new Behaviour(dgate_clone); //FIXME: b->m_promotionmanager = m_promotionmanager->clone(); b->m_promotionmanager = m_promotionmanager; return b; @@ -56,24 +59,22 @@ bool Behaviour::mayPromote(const IState* state, const Move& move) const { return false; // move starts or ends on the promotion rows on the other side ? + unsigned pzwidth; + Q_ASSERT(QMetaObject::invokeMethod(m_delegator, "promotionZoneWidth", + Q_RETURN_ARG(unsigned, pzwidth))); return ((state->turn() == Black::self()) ? - (move.src().y >= state->board()->size().y - m_delegator->promotionZoneWidth() || - move.dst().y >= state->board()->size().y - m_delegator->promotionZoneWidth()) : - (move.src().y < m_delegator->promotionZoneWidth() || - move.dst().y < m_delegator->promotionZoneWidth())); + (move.src().y >= state->board()->size().y - pzwidth || + move.dst().y >= state->board()->size().y - pzwidth) : + (move.src().y < pzwidth || + move.dst().y < pzwidth)); } void Behaviour::setDelegator(IBehaviour* behaviour) { Delegators::Behaviour::setDelegator(behaviour); - m_delegator = dynamic_cast(behaviour); - if (!m_delegator) { - kError() << "Behaviour::setDelegator needs a Shogi::Behaviour, cannot use a" - << typeid(behaviour).name(); - m_delegator = this; - } + m_delegator = behaviour; } -Component* Behaviour::clone(PromotionManager* pm) const { +IBehaviour* Behaviour::clone(PromotionManager* pm) const { Behaviour* b = dynamic_cast(clone()); // FIXME: cannot use static_cast ? Q_ASSERT(b); if (pm) diff --git a/src/variants/shogi/behaviour.h b/src/variants/shogi/behaviour.h index eaf1d10..52313e5 100644 --- a/src/variants/shogi/behaviour.h +++ b/src/variants/shogi/behaviour.h @@ -17,17 +17,17 @@ class Move; namespace Shogi { -class TAGUA_EXPORT Behaviour : public Component, virtual public Delegators::Behaviour { +class TAGUA_EXPORT Behaviour : public Delegators::Behaviour { Q_OBJECT PromotionManager* m_promotionmanager; - Behaviour* m_delegator; + IBehaviour* m_delegator; public: Behaviour(IBehaviour* behaviour); - virtual IBehaviour* clone() const; - virtual void captureOn(IState* state, const Point& square) const; + virtual void setDelegator(IBehaviour* behaviour); +public Q_SLOTS: void setPromotionManager(PromotionManager* pm) { m_promotionmanager = pm; kDebug() << this << "m_promotionmanager=" << m_promotionmanager; @@ -38,13 +38,10 @@ public: return m_promotionmanager; } - virtual bool mayPromote(const IState* state, const Move& move) const; - virtual unsigned promotionZoneWidth() const { return 3; } + bool mayPromote(const IState* state, const Move& move) const; + unsigned promotionZoneWidth() const { return 3; } - virtual void setDelegator(IBehaviour* behaviour); - -public Q_SLOTS: - virtual Component* clone(PromotionManager* pm) const; + virtual IBehaviour* clone(PromotionManager* pm) const; }; } // namespace Shogi diff --git a/src/variants/shogi/delegators/behaviour.h b/src/variants/shogi/delegators/behaviour.h index 57646f5..6feac93 100644 --- a/src/variants/shogi/delegators/behaviour.h +++ b/src/variants/shogi/delegators/behaviour.h @@ -14,6 +14,7 @@ class ShogiBehaviour : public Shogi::Behaviour { protected: Shogi::Behaviour* m_dgate_shogibehaviour; public: +#if 0 ShogiBehaviour(IBehaviour* behaviour) : Delegators::Behaviour(behaviour) , Shogi::Behaviour(behaviour), @@ -29,6 +30,24 @@ public: m_dgate_shogibehaviour->setDelegator(this); kDebug() << this << "m_dgate_shogibehaviour=" << m_dgate_shogibehaviour; } +#endif + + ShogiBehaviour(Component* behaviour) + : Delegators::Behaviour(dynamic_cast(behaviour)) + , Shogi::Behaviour(dynamic_cast(behaviour)), + m_dgate_shogibehaviour(NULL) { + Shogi::Behaviour* shogibehaviour = qobject_cast< Shogi::Behaviour* >(behaviour); + if (shogibehaviour == NULL) { + kError() << "Delegators::ShogiBehaviour needs a Shogi::Behaviour, cannot use a" + << typeid(behaviour).name(); + abort(); + } + + m_dgate_shogibehaviour = shogibehaviour; + m_dgate_shogibehaviour->setDelegator(this); + kDebug() << this << "m_dgate_shogibehaviour=" << m_dgate_shogibehaviour; + } + virtual ~ShogiBehaviour() { delete m_dgate_shogibehaviour; } virtual unsigned promotionZoneWidth() const { diff --git a/src/variants/shogi/shogi.cpp b/src/variants/shogi/shogi.cpp index ae945cc..6c06e89 100644 --- a/src/variants/shogi/shogi.cpp +++ b/src/variants/shogi/shogi.cpp @@ -43,11 +43,6 @@ taguashogi_initrepo(IVariantLoader* loader) { repo->addComponent("type/dragonhorse", DragonHorse::self()); repo->addComponent("type/tokin", Tokin::self()); -#if 0 - // create crazyhouse behaviour - IState* crazyhouse_state = requestInterface(crazyhouse->getComponent("state")); - repo->addComponent("state", new State(crazyhouse_state->behaviour(), Point(9, 9))); -#else IState* chess_state = requestInterface(chess->getComponent("state")); PromotionManager* promotion_manager = new PromotionManager(); promotion_manager->setPromotion(Silver::self(), Narigin::self()); @@ -59,11 +54,16 @@ taguashogi_initrepo(IVariantLoader* loader) { repo->addComponent("promotion_manager", promotion_manager); // base behaviour on chess - Behaviour* behaviour = new Behaviour(chess_state->behaviour()->clone()); + Component* chess_behaviour_comp = chess->getComponent("behaviour"); + Q_ASSERT(chess_behaviour_comp); + IBehaviour* behaviour_clone = NULL; + Q_ASSERT(QMetaObject::invokeMethod(chess_behaviour_comp, "clone", + Q_RETURN_ARG(IBehaviour*, behaviour_clone))); + Q_ASSERT(behaviour_clone); + Behaviour* behaviour = new Behaviour(behaviour_clone); behaviour->setPromotionManager(promotion_manager); repo->addComponent("behaviour", behaviour); repo->addComponent("state", new State(behaviour, Point(9, 9))); -#endif Validator* validator = new Validator; repo->addComponent("validator", validator); diff --git a/src/variants/shogi/types/bishop.cpp b/src/variants/shogi/types/bishop.cpp index c893570..40c3dd2 100644 --- a/src/variants/shogi/types/bishop.cpp +++ b/src/variants/shogi/types/bishop.cpp @@ -10,7 +10,8 @@ #include "bishop.h" -#include "../behaviour.h" +#include +#include #include #include @@ -42,10 +43,19 @@ bool Bishop::canMove(const Piece& piece, const Piece& target, if (!valid) return false; - const Behaviour* behaviour = dynamic_cast(state->behaviour()); - if (behaviour->mayPromote(state, move)) { + IBehaviour* behaviour = const_cast(state->behaviour()); + Q_ASSERT(behaviour); + bool may_promote; + Q_ASSERT(QMetaObject::invokeMethod(behaviour, "mayPromote", + Q_RETURN_ARG(bool, may_promote), + Q_ARG(const IState*, state), + Q_ARG(const Move, move))); // FIXME: Move& ? + if (may_promote) { move.setType("promotion"); - const IType* newtype = behaviour->promotionManager()->getPromotion(piece.type()); + const PromotionManager* pm; + Q_ASSERT(QMetaObject::invokeMethod(behaviour, "promotionManager", + Q_RETURN_ARG(const PromotionManager*, pm))); + const IType* newtype = pm->getPromotion(piece.type()); kDebug() << "promoting to" << newtype->name(); move.setPromotion(newtype); } -- 2.11.4.GIT