The Wayback Machine - http://web.archive.org/web/20201101224651/https://github.com/davecom/ClassicComputerScienceProblemsInPython/issues/10
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returned type should be int not float #10

Open
GreatBahram opened this issue Nov 1, 2019 · 1 comment
Open

Returned type should be int not float #10

GreatBahram opened this issue Nov 1, 2019 · 1 comment

Comments

@GreatBahram
Copy link

@GreatBahram GreatBahram commented Nov 1, 2019

Hello there,
I think, you should modify the type hints, since the xdist and ydist are both integer, so sum of them is going to be integer too, right?

def manhattan_distance(goal: MazeLocation) -> Callable[[MazeLocation], float]:
def distance(ml: MazeLocation) -> float:
xdist: int = abs(ml.column - goal.column)
ydist: int = abs(ml.row - goal.row)
return (xdist + ydist)
return distance

@davecom
Copy link
Owner

@davecom davecom commented Nov 22, 2019

Probably; we return float because we want consistency with Euclidean distance, and so that the type hints match with the heuristic parameter of astar(). The alternative is a float() conversion at the end of distance().

Thanks for pointing this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.