Skip to content
Permalink
Browse files

Make search_astar more stable across platforms

This function is used by slime levelgen in order to ensure level
connectivity that doesn't require touching slime walls, and because of
this use matters for seeding in slime (both because its behavior impacts
what wall squares get removed, and because this astar implementation
draws heavily on the rng. The implementation was behaving differently
across platforms.  Because slime is pretty independent of other
branches, the instability was localized to that branch, but usually
affected the entire thing.

The basic problem is that the search fringe was sorted only by distance
in the priority queue, so if two coordinates were the same distance,
their ordering in the queue was implementation-dependent (and was
differing on mac vs linux builds at least). This fix makes the sort
stable in such cases by comparing coordinates as well. This won't
necessarily do anything for the speed of the search (perhaps LIFO
behavior would be better)...

I wonder if this overall approach is really the best way to ensure
connectivity in slime? And why does this algorithm need randomization
(classic a-star doesn't)? But this code is complicated enough that I'm
not going to mess with it further right now.
  • Loading branch information...
rawlins committed Mar 13, 2019
1 parent 654ca03 commit d121a6d4c08e280d8ccc9d3a319aead044c9f153
Showing with 2 additions and 0 deletions.
  1. +2 −0 crawl-ref/source/nearby-danger.h
@@ -91,6 +91,8 @@ struct path_less
bool operator()(const set<position_node>::iterator & left,
const set<position_node>::iterator & right)
{
if (left->total_dist() == right->total_dist())
return left->pos > right->pos;
return left->total_dist() > right->total_dist();
}
};

0 comments on commit d121a6d

Please sign in to comment.
You can’t perform that action at this time.