Vector2d findBestPositionToAttack(const model::World& w, const model::Trooper& trooper, const model::Trooper& enemy){ Vector2d res(-1,-1); PathFinder pf; int bestDist = 1 << 20; const std::vector<std::vector<model::CellType> >& cells = w.getCells(); for (int i = 0; i < w.getWidth(); i++){ for (int j = 0; j < w.getHeight(); j++){ // if (enemy.getDistanceTo(i,j) > 8 || cells[i][j] != model::FREE || PathFinder::isTropperInCell(w,Vector2d(i,j))) //dist to check. Too much??? if (trooper.getDistanceTo(i,j) > 5 || cells[i][j] != model::FREE || PathFinder::isTropperInCell(w,Vector2d(i,j))) //dist to check. Too much??? continue; if (!w.isVisible(trooper.getShootingRange(), i, j, model::STANDING, enemy.getX(), enemy.getY(), enemy.getStance())) continue; std::list<Vector2d> path = pf.calcOptimalPath(w, Vector2d(trooper.getX(), trooper.getY()), Vector2d(i, j)); if(path.empty()) continue; std::list<Vector2d> pathWithoutPlayers = pf.calcOptimalPath(w, Vector2d(trooper.getX(), trooper.getY()), Vector2d(i, j), true); if (pathWithoutPlayers.size() + 3 < path.size()) continue; int dist = path.size(); if (dist < bestDist){ bestDist = dist; res = Vector2d(i,j); } } } return res; }
Vector2d processApproximate(const model::World& w, const Vector2d& appr){ Vector2d res; const std::vector<std::vector<model::CellType> >& cells = w.getCells(); float min = 1 << 20; for (int i = 0; i < w.getWidth(); i++) for (int j = 0; j < w.getHeight(); j++){ float d = dist(appr, Vector2d(i, j)); if (cells[i][j] == model::FREE && min > d){ min = d; res = Vector2d (i, j); } } return res; }
std::vector<Vector2d> getDstsWithDir(const model::World& w, const Vector2d susanin_v, const Vector2d dir){ std::vector<Vector2d> res; const std::vector<std::vector<model::CellType> >& cells = w.getCells(); for (int i = 0; i < w.getWidth(); i++) for (int j = 0; j < w.getHeight(); j++){ float d = dist(susanin_v, Vector2d(i, j)); if (d > kMinDist && d < kMaxDist && cells[i][j] == model::FREE && !PathFinder::isTropperInCell(w, Vector2d(i, j)) && isFeetDirection(susanin_v, i, j, dir)) res.push_back(Vector2d(i, j)); } return res; }