push 98438d20051787465e7a05f4aa66ab452afb1c14
[tagua/yd.git] / src / variants / chess / king.cpp
blobb51654e6e4821dd524d49687007b0388ebaef842
1 /*
2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2007 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #include "king.h"
12 #include <core/move.h>
14 #include "castlingrules.h"
16 namespace Chess {
18 King::King() { }
20 QString King::name() const { return "king"; }
22 bool King::canMove(const Piece& piece, const Piece&,
23 Move& move, const IState* state) const {
24 if (abs(move.delta().x) <= 1 && abs(move.delta().y) <= 1) return true;
25 if (m_castling_rules)
26 return m_castling_rules->canCastle(piece, move, state);
27 return false;
30 int King::index() const { return 10000; }
32 King* King::self() {
33 static King s_instance;
34 return &s_instance;
37 void King::setCastlingRules(Component* castlingRules) {
38 m_castling_rules = dynamic_cast<ICastlingRules*>(castlingRules);
39 if (!m_castling_rules) m_castling_rules = new CastlingRulesAdaptor(castlingRules, false);