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/state.h>
19 void Behaviour::captureOn(IState
* state
, const Point
& square
) const {
20 state
->board()->set(square
, Piece());
23 void Behaviour::move(IState
* state
, const Move
& m
) const {
24 if (m
.dst() != m
.src()) {
25 state
->board()->set(m
.dst(), state
->board()->get(m
.src()));
26 state
->board()->set(m
.src(), Piece());
30 void Behaviour::advanceTurn(IState
* state
) const {
31 state
->setTurn(opponent(state
->turn()));
34 Point
Behaviour::captureSquare(const IState
*, const Move
& m
) const {
35 if (m
.type() == "en_passant_capture")
36 return Point(m
.dst().x
, m
.src().y
);
41 const IColor
* Behaviour::opponent(const IColor
* player
) const {
42 return player
== White::self()
43 ? static_cast<IColor
*>(Black::self())
44 : static_cast<IColor
*>(White::self());
47 Point
Behaviour::direction(const IColor
* player
) const {
48 return Point(0, player
== White::self() ? -1 : 1);