refresh dc9ccb8c0bf4bc198802d4d39ad2bc523eb5e06f
[tagua/yd.git] / src / variants / shogi / shogi.cpp
blob6c06e892cdaef6e5c890ca9702f7264d5b1a9090
1 #include <core/repository.h>
2 #include <core/variantloader.h>
4 #include "behaviour.h"
5 #include "colors.h"
6 #include "moveserializer.h"
7 #include "types.h"
8 #include "state.h"
9 #include "validator.h"
11 using namespace Shogi;
13 extern "C" KDE_EXPORT Repository*
14 taguashogi_initrepo(IVariantLoader* loader) {
15 Repository* repo = new Repository;
16 Repository* chess = loader->getRepository("chess");
17 if (!chess)
18 // bail out if there is no chess variant
19 return 0;
20 #if 0
21 Repository* crazyhouse = loader->getRepository("crazyhouse");
22 if (!crazyhouse)
23 // bail out if there is no crazyhouse variant
24 return 0;
25 #endif
27 repo->addComponent("player/0", dynamic_cast<Component*>(COLORS[0]));
28 repo->addComponent("player/1", dynamic_cast<Component*>(COLORS[1]));
30 repo->addComponent("type/king", King::self());
31 repo->addComponent("type/gold", Gold::self());
32 repo->addComponent("type/silver", Silver::self());
33 repo->addComponent("type/knight", Knight::self());
34 repo->addComponent("type/lance", Lance::self());
35 repo->addComponent("type/rook", Rook::self());
36 repo->addComponent("type/bishop", Bishop::self());
37 repo->addComponent("type/pawn", Pawn::self());
39 repo->addComponent("type/narigin", Narigin::self());
40 repo->addComponent("type/narikei", Narikei::self());
41 repo->addComponent("type/narikyo", Narikyo::self());
42 repo->addComponent("type/dragonking", DragonKing::self());
43 repo->addComponent("type/dragonhorse", DragonHorse::self());
44 repo->addComponent("type/tokin", Tokin::self());
46 IState* chess_state = requestInterface<IState>(chess->getComponent("state"));
47 PromotionManager* promotion_manager = new PromotionManager();
48 promotion_manager->setPromotion(Silver::self(), Narigin::self());
49 promotion_manager->setPromotion(Knight::self(), Narikei::self());
50 promotion_manager->setPromotion(Lance::self(), Narikyo::self());
51 promotion_manager->setPromotion(Rook::self(), DragonKing::self());
52 promotion_manager->setPromotion(Bishop::self(), DragonHorse::self());
53 promotion_manager->setPromotion(Pawn::self(), Tokin::self());
54 repo->addComponent("promotion_manager", promotion_manager);
56 // base behaviour on chess
57 Component* chess_behaviour_comp = chess->getComponent("behaviour");
58 Q_ASSERT(chess_behaviour_comp);
59 IBehaviour* behaviour_clone = NULL;
60 Q_ASSERT(QMetaObject::invokeMethod(chess_behaviour_comp, "clone",
61 Q_RETURN_ARG(IBehaviour*, behaviour_clone)));
62 Q_ASSERT(behaviour_clone);
63 Behaviour* behaviour = new Behaviour(behaviour_clone);
64 behaviour->setPromotionManager(promotion_manager);
65 repo->addComponent("behaviour", behaviour);
66 repo->addComponent("state", new State(behaviour, Point(9, 9)));
68 Validator* validator = new Validator;
69 repo->addComponent("validator", validator);
70 repo->addComponent("animator_factory", chess->getComponent("animator_factory"));
71 repo->addComponent("namer", chess->getComponent("namer"));
72 repo->addComponent("policy", chess->getComponent("policy"));
74 // set move serializers
75 Repository::ComponentMap serializers = chess->listComponents("move_serializer");
76 for (Repository::ComponentMap::const_iterator it = serializers.begin(),
77 end = serializers.end(); it != end; ++it) {
78 IMoveSerializer* s = requestInterface<IMoveSerializer>(it.value());
79 if (s) repo->addComponent("move_serializer/" + it.key(), new MoveSerializer(s));
82 return repo;