Skip to content

The path found is not the shortest path #3

@miblooming

Description

@miblooming

In the code, the distance estimation uses the "Chebyshev distance", which will result in the path found not being the shortest path. The "Manhattan distance" should be used.

public static int GetDist(Point a, Point b)
{
	int diff_columns = Mathf.Abs( b.column - a.column );
	int diff_rows    = Mathf.Abs( b.row - a.row );

	int d1 = diff_rows;
	int d2 = diff_columns;
	if (d1 > d2)
	{
		(d1, d2) = (d2, d1);
	}

	return (d2 - d1) + (int)(d1 * SQRT_2 );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions