Skip to content

Commit

Permalink
Fixed pydoc comment on distance_to (#199)
Browse files Browse the repository at this point in the history
* Fixed pydoc comment on distance_to

* Corrected comments for to_index, from_index

inverse function names were wrong
  • Loading branch information
dgrunberg authored Dec 11, 2024
1 parent 3485625 commit c492b6a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions kaggle_environments/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def translate(self, offset: 'Point', size: int):
return (self + offset) % size

def distance_to(self, other: 'Point', size: int):
"""Translates the current point by offset and wraps it around a board of width and height size"""
"""Computes total distance (manhattan) to travel to other Point"""
abs_x = abs(self.x - other.x)
dist_x = abs_x if abs_x < size/2 else size - abs_x
abs_y = abs(self.y - other.y)
Expand All @@ -46,15 +46,15 @@ def distance_to(self, other: 'Point', size: int):
def to_index(self, size: int):
"""
Converts a 2d position in the form (x, y) to an index in the observation.halite list.
See index_to_position for the inverse.
See staticmethod from_index for the inverse.
"""
return (size - self.y - 1) * size + self.x

@staticmethod
def from_index(index: int, size: int) -> 'Point':
"""
Converts an index in the observation.halite list to a 2d position in the form (x, y).
See position_to_index for the inverse.
See Point method to_index for the inverse.
"""
y, x = divmod(index, size)
return Point(x, (size - y - 1))
Expand Down

0 comments on commit c492b6a

Please sign in to comment.