minor changes to path finding

This commit is contained in:
Dave White 2003-10-28 10:09:20 +00:00
parent 0fbc023fc7
commit f8dfddfe78
2 changed files with 16 additions and 2 deletions

View file

@ -105,6 +105,18 @@ bool tiles_adjacent(const gamemap::location& a, const gamemap::location& b)
xdiff == 1 && ydiff == 1 && (a.y > b.y ? (a.x%2) == 1 : (b.x%2) == 1);
}
size_t distance_between(const gamemap::location& a, const gamemap::location& b)
{
const size_t hdistance = abs(a.x - b.x);
const size_t vpenalty = (is_even(a.x) && is_odd(b.x) && a.y < b.y ||
is_even(b.x) && is_odd(a.x) && b.y < a.y) ? 1:0;
const size_t vdistance = abs(a.y - b.y) + vpenalty;
const size_t vsavings = minimum(vdistance,hdistance/2 + hdistance%2);
return hdistance + vdistance - vsavings;
}
bool enemy_zoc(const gamemap& map,const std::map<gamemap::location,unit>& units,
const gamemap::location& loc, const team& current_team, int side)
{

View file

@ -28,6 +28,8 @@
void get_adjacent_tiles(const gamemap::location& a, gamemap::location* res);
bool tiles_adjacent(const gamemap::location& a, const gamemap::location& b);
size_t distance_between(const gamemap::location& a, const gamemap::location& b);
gamemap::location find_vacant_tile(const gamemap& map,
const std::map<gamemap::location,unit>& un,
const gamemap::location& loc,
@ -75,10 +77,9 @@ namespace detail {
struct node {
static double heuristic(const gamemap::location& src,
const gamemap::location& dst) {
return sqrt(pow(abs(dst.x-src.x),2) + pow(abs(dst.y-src.y),2));
return distance_between(src,dst);
}
node(const gamemap::location& pos, const gamemap::location& dst,
double cost, node* parent,
const std::set<gamemap::location>* teleports)
@ -86,6 +87,7 @@ struct node {
{
//if there are teleport locations, correct the heuristic to
//take them into account
if(teleports != NULL) {
double srch = h, dsth = h;
std::set<gamemap::location>::const_iterator i;