Esempio n. 1
0
std::vector<int> GameState::getPath(int aSrc, int aTgt) const
{
    if (grid_.offGrid(aSrc) || grid_.offGrid(aTgt)) return {};

    Pathfinder pf;
    pf.setNeighbors([&] (int aIndex) {return getOpenNeighbors(aIndex);});
    pf.setGoal(aTgt);
    return pf.getPathFrom(aSrc);
}
Esempio n. 2
0
std::vector<int> GameState::getReachableHexes(const Unit &unit) const
{
    std::vector<int> reachable;

    // Flying units don't need a clear path.
    if (unit.canFly()) {
        for (int i = 0; i < grid_.size(); ++i) {
            if (isHexFlyable(unit, i)) {
                reachable.push_back(i);
            }
        }
    }
    else {
        Pathfinder pf;
        pf.setNeighbors([&] (int aIndex) {return getOpenNeighbors(aIndex);});
        reachable = pf.getReachableNodes(unit.aHex, unit.type->moves);
    }

    return reachable;
}