Preliminary port of Shogi to the component API.
[tagua/yd.git] / src / variants / shogi / type.cpp
bloba4ca0d6bb901de41c7bcd92d786c3fb8d8ba140d
1 #include "type.h"
3 #include <core/behaviour.h>
4 #include <core/promotionmanager.h>
5 #include <core/state.h>
6 #include <core/move.h>
8 #include <KDebug>
10 namespace Shogi {
12 bool Type::canMove(const Piece& piece, const Piece& target,
13 Move& move, const IState* state) const {
14 bool valid = DefaultType::canMove(piece, target, move, state);
15 if (!valid)
16 return false;
18 IBehaviour* behaviour = const_cast<IBehaviour*>(state->behaviour());
19 Q_ASSERT(behaviour);
20 bool may_promote;
21 Q_ASSERT(QMetaObject::invokeMethod(behaviour, "mayPromote",
22 Q_RETURN_ARG(bool, may_promote),
23 Q_ARG(const IState*, state),
24 Q_ARG(const Move, move))); // FIXME: Move& ?
25 if (may_promote) {
26 move.setType("promotion");
27 const PromotionManager* pm;
28 Q_ASSERT(QMetaObject::invokeMethod(behaviour, "promotionManager",
29 Q_RETURN_ARG(const PromotionManager*, pm)));
30 const IType* newtype = pm->getPromotion(piece.type());
31 kDebug() << "promoting to" << newtype->name();
32 move.setPromotion(newtype);
35 return true;
38 } // namespace Shogi