Tentative MiniShogi implementation over move generator.
[tagua/yd.git] / src / variants / minishogi / minishogi.cpp
blob4b5628a2383a7a2786bcefe3c5debb93d12bcec9
1 #include "behaviour.h"
2 #include "state.h"
4 #include <core/color.h>
5 #include <core/point.h>
6 #include <core/repository.h>
7 #include <core/variantloader.h>
8 #include <core/state.h>
9 #include <core/type.h>
11 #include <KDebug>
13 using namespace MiniShogi;
15 #define LOAD_TYPE(NAME) \
16 NAME = requestInterface<IType>(shogi->getComponent("type/" #NAME))
18 namespace MiniShogi {
19 const IType* pawn;
20 const IType* king;
21 const IType* gold;
22 const IType* silver;
23 const IType* bishop;
24 const IType* rook;
25 const IColor* players[2];
28 extern "C" KDE_EXPORT Repository*
29 taguaminishogi_initrepo(IVariantLoader* loader) {
30 Repository* repo = new Repository;
31 Repository* shogi = loader->getRepository("shogi");
32 if (!shogi)
33 // bail out if there is no shogi variant
34 return 0;
36 repo->setProxy(shogi);
38 // get shogi state factory
39 Component* shogi_state_comp = shogi->getComponent("state");
40 IState* shogi_state = requestInterface<IState>(shogi_state_comp);
42 // base behaviour on shogi
43 Component* shogi_behaviour_comp = shogi->getComponent("behaviour");
44 Q_ASSERT(shogi_behaviour_comp);
45 IBehaviour* behaviour_clone = NULL;
46 Q_ASSERT(QMetaObject::invokeMethod(shogi_behaviour_comp, "clone",
47 Q_RETURN_ARG(IBehaviour*, behaviour_clone),
48 Q_ARG(PromotionManager*, NULL)));
49 Q_ASSERT(behaviour_clone);
50 Behaviour* behaviour = new Behaviour(behaviour_clone);
52 // create minishogi state factory
53 IState* state_clone = 0;
54 Q_ASSERT(QMetaObject::invokeMethod(shogi_state_comp, "clone",
55 Q_RETURN_ARG(IState*, state_clone),
56 Q_ARG(const IBehaviour*, behaviour),
57 Q_ARG(Point, Point(5, 5))));
58 Q_ASSERT(state_clone);
59 State* state = new State(state_clone);
61 // set state factory
62 repo->addComponent("state", state);
64 LOAD_TYPE(pawn);
65 LOAD_TYPE(king);
66 LOAD_TYPE(gold);
67 LOAD_TYPE(silver);
68 LOAD_TYPE(bishop);
69 LOAD_TYPE(rook);
70 players[0] = Black::self();
71 players[1] = White::self();
73 return repo;