-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposClass.py
60 lines (46 loc) · 1.43 KB
/
posClass.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from random import randrange
from func import maze
class pos:
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return "{" + str(self.x) + "," + str(self.y) + "}"
def distance(self, other):
return (abs(other.x - self.x) ** 2) + (abs(other.y - self.y) ** 2)
def sum(self, other):
return pos(self.x + other.x, self.y + other.y)
def mult(self, i: int):
return pos(self.x * i, self.y * i)
def flip(self, mirror):
return pos(mirror.x - (self.x - mirror.x), mirror.y - (self.y - mirror.y))
def equal(self,x,y):
return self.x==x and self.y==y
def dirSum(self,d:str):
return self.sum(posMap.get(d))
def __eq__(self,other):
return self.x==other.x and self.y == other.y
def inRange(self):
return 0 <= self.x <= 18
def wrap(self):
if(self.x<0):return pos(18,self.y)
elif(self.x>18):return pos(0,self.y)
else:return self
def asArr(self):
return [self.x,self.y]
posMap = {"u": pos(0, -1), "d": pos(0, 1), "l": pos(-1, 0), "r": pos(1, 0)}
def genRandPos():
y = randrange(1,len(maze)-1)
x=0
list = maze[y]
go = True
while go:
x=randrange(len(list))
if list[x]!=" ":go = False
return pos(x, y)
def opp(d: str):
if d == "u": return "d"
if d == "d": return "u"
if d == "l": return "r"
if d == "r": return "l"
else:return d