-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelper.py
More file actions
65 lines (50 loc) · 1.32 KB
/
helper.py
File metadata and controls
65 lines (50 loc) · 1.32 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from Setting import *
from math import sqrt,fabs
import pygame
def Get(name, delta = 0):
name = "CTF/Data/" + name + ".png"
print (name)
image = pygame.image.load(name)
image = pygame.transform.scale(
image,
(CELL_WIDTH + delta, CELL_HEIGHT + delta)
)
return image
def Hash(s):
if (s == NORTH):
return "NORTH"
if (s == SOUTH):
return "SOUTH"
if (s == EAST):
return "EAST"
return "WEST"
def Manhattan(a, b, x, y, D = 1):
return D * abs(a - x) + abs(b - y)
def Euclidean(a, b, x, y, D = 1):
dx = abs(a - x)
dy = abs(b - y)
return D * sqrt(dx * dx + dy * dy)
class Path :
def __init__(self, path, costTable):
self.path = path
self.costTable = costTable
def pop(self):
return self.path.pop()
def append(self, el):
self.path.append(el)
def xySwap(self):
for i in range(len(self.path)):
self.path[i].swap()
def reverse(self):
self.path.reverse()
def isEmpty(self):
return len(self.path) == 0
def __str__(self):
s = ""
for el in self.path:
s += str(el)
return s
def __eq__(self, other):
return(
self.path == other.path
)