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.
10 #include "behaviour.h"
12 #include <core/board.h>
13 #include <core/color.h>
14 #include <core/move.h>
15 #include <core/piece.h>
16 #include <core/poolcollection.h>
17 #include <core/pool.h>
18 #include <core/state.h>
22 Behaviour::Behaviour(const IBehaviour
* behaviour
)
23 : Delegators::Behaviour(behaviour
) { }
25 void Behaviour::captureOn(IState
* state
, const Point
& square
) const {
26 Piece
* captured
= state
->board()->get(square
);
27 if (captured
!= NULL
&& *captured
!= Piece()) {
28 if (captured
->get("promoted").toBool()) {
29 captured
->setType(m_promotionmanager
->getDepromotion(captured
->type()));
31 state
->pools()->pool(opponent(captured
->color()))->insert(-1, *captured
);
33 m_behaviour
->captureOn(state
, square
);
36 bool Behaviour::mayPromote(const IState
* state
, const Move
& move
) const {
37 // promoted piece cannot promote again
41 // does that piece type can even promote ?
42 if (promotionManager()->getPromotion(state
->board()->get(move
.src())->type()) == NULL
)
45 // move starts or ends on the 3 rows on the other side ?
46 return ((state
->turn() == Black::self()) ?
47 (move
.src().y
>= 6 || move
.dst().y
>= 6) :
48 (move
.src().y
<= 2 || move
.dst().y
<= 2));