Skip to content

Commit

Permalink
fix #5411
Browse files Browse the repository at this point in the history
  • Loading branch information
rtri committed Dec 3, 2016
1 parent ae0ef2f commit e41d9be
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions rts/Sim/Path/Default/PathFinderDef.cpp
Expand Up @@ -31,13 +31,16 @@ bool CPathFinderDef::IsGoal(unsigned int xSquare, unsigned int zSquare) const {
// returns distance to goal center in heightmap-squares
float CPathFinderDef::Heuristic(unsigned int xSquare, unsigned int zSquare, unsigned int blockSize) const
{
const float s = 1.0f / blockSize;
const float dx = std::abs(int(xSquare) - int(goalSquareX)) * s;
const float dz = std::abs(int(zSquare) - int(goalSquareZ)) * s;
(void) blockSize;

// grid is 8-connected, so use octile distance (normalized by block-size)
constexpr const float C1 = 1.0f;
constexpr const float C2 = 1.4142f - (2.0f * C1);
const float dx = std::abs(int(xSquare) - int(goalSquareX));
const float dz = std::abs(int(zSquare) - int(goalSquareZ));

// grid is 8-connected, so use octile distance metric
// note that using C1=1 and C2=sqrt(2) will over-estimate
// on terrain with extreme speed modifiers, so scale both
constexpr const float C1 = 1.0f * 0.5f;
constexpr const float C2 = 1.4142f * 0.5f - (2.0f * C1);
return ((dx + dz) * C1 + std::min(dx, dz) * C2);
}

Expand Down

9 comments on commit e41d9be

@ashdnazg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe instead of scaling by an arbitrary number, scale by the highest known speed modifier?

@rtri
Copy link
Contributor

@rtri rtri commented on e41d9be Jan 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's what I switched to a few commits after this one.

@ashdnazg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great minds etc. :P

@ashdnazg
Copy link
Member

@ashdnazg ashdnazg commented on e41d9be Jan 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although, wouldn't you want to add the multiplier here as well?

const float hCost = pfDef.Heuristic(square.x, square.y, BLOCK_SIZE); // h

@ashdnazg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or here:

const float heurGoalDist2D = pfDef->Heuristic(startPos.x / SQUARE_SIZE, startPos.z / SQUARE_SIZE, 1) + math::fabs(goalPos.y - startPos.y) / SQUARE_SIZE;

@rtri
Copy link
Contributor

@rtri rtri commented on e41d9be Jan 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first case: technically yes, but the PF is used over such short distances that suboptimal paths should not be a problem (famous last words).

making heurGoalDist2D smaller will engage the higher-res layers more often, could be risky.

@ashdnazg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough

@ashdnazg
Copy link
Member

@ashdnazg ashdnazg commented on e41d9be Jan 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm daft, ignore

@rtri
Copy link
Contributor

@rtri rtri commented on e41d9be Jan 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's an inverse scaling, the heuristic multiplier is 1 / max_speedmod

Please sign in to comment.