7df4508fd7741c717731daf7346b2db31d0f3413
[tagua/yd.git] / src / core / defaultstate.cpp
blob7df4508fd7741c717731daf7346b2db31d0f3413
1 #include "behaviour.h"
2 #include "board.h"
3 #include "defaultstate.h"
4 #include "defaulttype.h"
6 std::vector<const Point*> DefaultState::theoreticalMoves(const Piece& piece,
7 const Point& src) const {
8 std::vector<const Point*> destinations;
10 const IBehaviour* behaviour = this->behaviour();
11 if (!behaviour) return destinations; // empty
13 const std::vector<MoveDefinition> * defs =
14 dynamic_cast<const DefaultType*>(piece.type())->movesDefinitions();
15 if (!defs) return destinations; // empty
17 //kDebug() << "looking at moves from " << src;
18 for (unsigned direction=0; direction < defs->size(); direction++)
19 for (int distance=1;
20 (*defs)[direction].distance ? (distance <= (*defs)[direction].distance) : 1;
21 distance++) {
22 Point* candidate = new Point(src.x + ((*defs)[direction].x * distance *
23 -behaviour->direction(piece.color()).y),
24 src.y + ((*defs)[direction].y * distance *
25 behaviour->direction(piece.color()).y));
26 if (!board()->valid(*candidate))
27 // end of board: don't look further in that direction
28 break;
30 destinations.push_back(candidate);
32 // stop looking in direction if there is a piece blocking move here
33 const Piece otherPiece = board()->get(*candidate);
34 if (otherPiece != Piece())
35 break;
38 return destinations;