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

Add square_manhattan_distance and square_knight_distance functions #986

Merged
merged 3 commits into from
Apr 16, 2023

Conversation

AInnuganti
Copy link
Contributor

The chess library includes a function called square_distance, which calculates the Chebyshev distance (number of king steps) between 2 squares. This way of measuring distance is not always sufficient though, so I added two new distance functions.

  • square_manhattan_distance calculates the Manhattan or Taxicab distance between 2 squares. This is the minimal number of orthogonal king moves it would take to travel from one square to another.

  • square_knight_distance calculates the knight distance (using a pretty weird formula), which is the minimal number of knight moves to travel from one square to another

Copy link
Owner

@niklasf niklasf left a comment

Choose a reason for hiding this comment

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

Thanks! Looks like a useful and consistent addition.

Some tests in test.py (class SquareTestCase) would be good, especially for the knight distance.

chess/__init__.py Outdated Show resolved Hide resolved
chess/__init__.py Outdated Show resolved Hide resolved
@AInnuganti
Copy link
Contributor Author

Alright both of those changes have been made. I can add some test cases later

@AInnuganti
Copy link
Contributor Author

I've added tests for square_manhattan_distance and square_knight_distance, and just for good measure, also added some for square_distance. Everything seems to be in working order

@niklasf niklasf merged commit 5a3cda8 into niklasf:master Apr 16, 2023
@niklasf
Copy link
Owner

niklasf commented Apr 16, 2023

Looks good. Merging.

niklasf added a commit that referenced this pull request Apr 16, 2023
@AInnuganti AInnuganti deleted the distance branch April 16, 2023 15:23
@niklasf niklasf added this to the v1.10.0 milestone Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants