-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
44 lines (32 loc) · 951 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pygame
def aborted() -> bool:
"""Checks if function has been aborted"""
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
return True
class Heuristic:
"""Class with basic heuristics"""
@staticmethod
def octil(p1, p2):
x1, y1 = p1
x2, y2 = p2
(ty, tx) = (abs(y1 - y2), abs(x1 - x2))
return max(ty, tx) + (2**0.5 - 1) * min(ty, tx)
@staticmethod
def manhattan(p1, p2):
x1, y1 = p1
x2, y2 = p2
return abs(x1 - x2) + abs(y1 - y2)
@staticmethod
def chebyshev(p1, p2):
x1, y1 = p1
x2, y2 = p2
return max(abs(y1 - y2), abs(x1 - x2))
@staticmethod
def euclidean(p1, p2):
x1, y1 = p1
x2, y2 = p2
return ((y1 - y2) ** 2 + (x1 - x2) ** 2) ** 0.5