Make component interfaces inherit Component.
[tagua/yd.git] / src / variants / chess / behaviour.cpp
blob8ab83849db7a8a042448df0e12f492fbb82ea384
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/color.h>
14 #include <core/move.h>
15 #include <core/state.h>
17 namespace Chess {
19 Behaviour::Behaviour()
20 : IBehaviour() { }
21 Behaviour::Behaviour(const Behaviour& other)
22 : IBehaviour() { }
24 void Behaviour::captureOn(IState* state, const Point& square) const {
25 state->board()->set(square, Piece());
28 void Behaviour::move(IState* state, const Move& m) const {
29 if (m.dst() != m.src()) {
30 state->board()->set(m.dst(), state->board()->get(m.src()));
31 state->board()->set(m.src(), Piece());
35 void Behaviour::advanceTurn(IState* state) const {
36 state->setTurn(opponent(state->turn()));
39 Point Behaviour::captureSquare(const IState*, const Move& m) const {
40 if (m.type() == "en_passant_capture")
41 return Point(m.dst().x, m.src().y);
42 else
43 return m.dst();
46 const IColor* Behaviour::opponent(const IColor* player) const {
47 return player == White::self()
48 ? static_cast<IColor*>(Black::self())
49 : static_cast<IColor*>(White::self());
52 Point Behaviour::direction(const IColor* player) const {
53 return Point(0, player == White::self() ? -1 : 1);
56 IBehaviour* Behaviour::clone() const {
57 return new Behaviour(*this);
60 } // namespace Chess