Finalize support for delegating behaviours.
[tagua/yd.git] / src / variants / crazyhouse / behaviour.cpp
blob8434e2e4e9502cee8dfd1b4d1c33f5a5d52250bb
1 /*
2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 */
10 #include "behaviour.h"
12 #include <core/board.h>
13 #include <core/piece.h>
14 #include <core/poolcollection.h>
15 #include <core/pool.h>
16 #include <core/state.h>
17 #include "global.h"
19 namespace Crazyhouse {
21 Behaviour::Behaviour(IBehaviour* behaviour)
22 : Delegators::Behaviour(behaviour) { }
24 IBehaviour* Behaviour::clone() const {
25 IBehaviour* dgate_clone;
26 Q_ASSERT(QMetaObject::invokeMethod(m_dgate_behaviour, "clone",
27 Q_RETURN_ARG(IBehaviour*, dgate_clone)));
28 return new Behaviour(dgate_clone);
31 void Behaviour::captureOn(IState* state, const Point& square) const {
32 Piece captured = state->board()->get(square);
33 if (captured != Piece()) {
34 if (captured.get("promoted").toBool()) {
35 captured.setType(pawn);
37 state->pools()->pool(opponent(captured.color()))->insert(-1, captured);
39 m_dgate_behaviour->captureOn(state, square);
42 } // namespace Crazyhouse