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; }