Utility Functions¶
-
vindinium.utils.
dir_to_command
(dx, dy)[source]¶ Converts a direction to a command.
Parameters: - dx (int) – direction in X axis, must be 1, 0 or -1.
- dy (int) – direction in Y axis, must be 1, 0 or -1.
Returns: (string) a command.
- Raise:
- ValueError if direction is invalid.
-
vindinium.utils.
command_to_dir
(command)[source]¶ Converts a command to a direction.
Parameters: the command. ((string)) – Returns: (tuple) a tuple (dx, dy) with the direction. - Raise:
- ValueError if command is invalid.
-
vindinium.utils.
path_to_command
(x0, y0, x1, y1)[source]¶ Converts an adjacent to a command.
Parameters: - x0 (int) – initial position in X axis.
- y0 (int) – initial position in Y axis.
- x1 (int) – final position in X axis.
- y1 (int) – final position in Y axis.
Returns: (string) a command.
- Raise:
- ValueError if direction is invalid.
-
vindinium.utils.
distance_manhattan
(x0, y0, x1, y1)[source]¶ Computes the manhattan distance between two points.
Parameters: - x0 (int) – initial position in X axis.
- y0 (int) – initial position in Y axis.
- x1 (int) – final position in X axis.
- y1 (int) – final position in Y axis.
Returns: (int) the distance.
-
vindinium.utils.
order_by_distance
(x, y, objects)[source]¶ Returns a list of objects ordered by distance from a given point.
You can use this to order mines or taverns by their distances from the hero.
Parameters: - x (int) – position in X.
- y (int) – position in Y.
- objects (list) – list of objects. The objects must implement the
- x and y. (attributes) –
Returns: (list) an ordered copy of
objects
.