refresh bdc45694d411cad215e68161e75bb9f1a8a39e47
[tagua/yd.git] / src / variants / shogi / faces / lance.cpp
blobc5436985b538988e125d289f7afbfdc95366cf69
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 "lance.h"
12 #include <core/behaviour.h>
13 #include <core/board.h>
14 #include <core/move.h>
15 #include <core/pathinfo.h>
16 #include <core/state.h>
18 namespace Shogi {
19 namespace Faces {
21 Lance::Lance() { }
23 QString Lance::name() const { return "lance"; }
25 bool Lance::canMove(const Piece& piece, const Piece&,
26 Move& move, const IState* state) const {
27 const IBehaviour* behaviour = state->behaviour();
28 if (!behaviour) return false;
29 PathInfo path = state->board()->path(move.src(), move.dst());
30 return move.delta().x == 0 &&
31 path.clear() &&
32 (move.delta().y * behaviour->direction(piece.color()).y > 0);
35 int Lance::index() const { return 40; }
37 Lance* Lance::self() {
38 static Lance s_instance;
39 return &s_instance;