the time taken to explore a level (and didn't reduce zig-zagging, like I thought it did). The next two algorithms I tried didn't work either; looks like avoiding back-tracking doesn't speed up auto-explore. So I got rid of all of that and concentrated just on reducing zig-zagging, which altough it has no in-game problems is visually annoying (to me, at least). Stats:
For most level types the increase in the number of turns auto-explore takes is no more than 1%, but on "city" like leves (as in the Vaults) and in the Shaols the increase can be from 7% to 13%; in the Swamps it doesn't make any difference.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3094 c06c8d41-db1a-0410-9941-cceddc491573
H3EEUJYQCVEXQSDP62GBIC47T4BKBAC4Z65HRKGJK2M5MFXZWYOAC
C6QWJ7O4HS2IGJZTDQLGFPXPD5OBFS4U364IRZFV7V2LXVPP4DXQC
OXCCCC5YQ5SDZDRLDQC4T7JOD4CUVCC6BX3JSOEPL5EWQX36CBMAC
RC6L3CIBLJEH4GWRFD7UQNGI6PZT74FRUVOYHSAN2XCC74NZUASQC
SDLKLUNFGVKDS55DDJZCBAVIB7NL3RRYPTACAY65SCUQKV6APFSAC
F2ZJ55CL3T66DFM34BQWCJNHIT4XJFCGTWTA5KESV6NHWFLTGUYAC
SSQP7MS6LZYY73QEF66EYNNQJJSB6TVLLWXLWL7JJAYBLXCEY2XAC
V26TVLNNESUAUJY24SEXIWRQB7A4JJ6TVQU3JVZV54IEEKCB3WOQC
RPOZZWKG5GLPHVZZ7ZKMKS64ZMV2LDCQSARBJFJ6FZOTOKCQO7FAC
RVST2QHYJ757ZHK4AUJ5NGPDZ44AD6RVFVXYPKQIBJXZBDNUCHXQC
// "Improved" explore: keep moving in a line along the same
// direction as the previous move, stop if we hit a barrier or
// something that would slow us down, and use *that* as the
// floodout seed. This is meant to:
//
// 1) Prevent explore from sticking its head in a room and then
// backing out even though the room has unexplored corners
// because there are unexplored squares closer than the corners.
//
// 2) Similarly, prevent the behavior of going a little bit down
// a long, straight corridor only to back out of it because
// the nearest unexplored square in that corridor is
// LOS_RADIUS + 1 squares away, which is further away than
// another unexplored square which is in the opposite direction.
//
// 3) Prevent the annoying zig-zag when exploring open spaces.
//
// We stop at squares that would slow us down so that we won't slog
// across a bunch of shallow water just for the sake of going in
// a straight line.
//
// Not yet used with greedy explore because I can't figure out
// how to combined it with greediness in a way that won't display
// weird or unintuitive behavior.
if (you.running != RMODE_EXPLORE_GREEDY && Options.explore_improved
&& (you.prev_move_x || you.prev_move_y))
{
coord_def prev_move_delta = you.prev_move();
prev_travel_moves[0] = -1;
prev_travel_moves[1] = -1;
prev_travel_index = 0;
anti_zigzag_dir = -1;
}
dungeon_feature_type feature;
do {
seed += prev_move_delta;
feature = grd(seed);
} while (is_travelsafe_square(seed.x, seed.y)
&& is_traversable(feature)
&& feature_traverse_cost(feature) == 1);
static void set_target_square(const coord_def &target)
{
you.running.x = target.x;
you.running.y = target.y;
// Has moving along the straight line found an unexplored
// square? If so, just use that square as the target.
if (!is_terrain_seen(seed + prev_move_delta) && seed != you.pos())
{
you.running.x = seed.x;
you.running.y = seed.y;
return;
}
}
tp.set_floodseed(seed, true);
static void explore_find_target_square()
{
travel_pathfind tp;
tp.set_floodseed(you.pos(), true);
you.running.x = whereto.x;
you.running.y = whereto.y;
// Anti-zigzag turned off, or found a greedy target so we
// don't need anti-zigzaging.
if (!Options.explore_improved || whereto != tp.unexplored_square())
{
set_target_square(whereto);
reset_zigzag_info();
return;
}
// If the two previous travel moves are perpendicular to each
// other and the two previous explore targets are close to each
// other, then we're probably zigzaging.
if (prev_travel_moves[0] != -1
&& prev_travel_moves[1] != -1
&& (abs(prev_travel_moves[1] - prev_travel_moves[0]) % 4) == 2
&& grid_distance(prev_explore_target.x, prev_explore_target.y,
whereto.x, whereto.y) <= (LOS_RADIUS + 1))
{
// Try moving along the line that bisects the right angle.
if (abs(prev_travel_moves[0] - prev_travel_moves[1]) == 6)
anti_zigzag_dir = 0;
else
anti_zigzag_dir = std::min(prev_travel_moves[0],
prev_travel_moves[1]) + 1;
}
// anti_zigzag_dir might have just been set, or might have
// persisted from the previous call to
// explore_find_target_square().
if (anti_zigzag_dir != -1)
{
coord_def target = you.pos();
coord_def delta = Compass[anti_zigzag_dir];
dungeon_feature_type feature;
do {
target += delta;
feature = grd(target);
} while (is_travelsafe_square(target.x, target.y)
&& is_traversable(feature)
&& feature_traverse_cost(feature) == 1);
target -= delta;
// Has moving along the straight line found an unexplored
// square?
if (!is_terrain_seen(target + delta) && target != you.pos())
{
set_target_square(target);
return;
}
else
anti_zigzag_dir = -1;
}
set_target_square(whereto);
If set to true explore will used an expiremental improved algorithm
which is meant to reduce backtracking and zig-zagging. Currently
only works with non-greedy explore.
If set to true explore will attempt to reduce zig-zagging during
auto-explore. In most circumstances this will increase the
number of turns spent to auto-explore an entire level by
less than 1% (with a 2% increase the maximum), but with
a 7% to 13% increase in the Shoals and in city-type levels
such as those found in the Vaults.