-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgent.py
More file actions
103 lines (87 loc) · 3.45 KB
/
Agent.py
File metadata and controls
103 lines (87 loc) · 3.45 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
class Agent:
direction = 2 # 0 N, 1 E, 2 S, 3 W
x = 1
y = 1
#myWall = None
#Wall myWall[][]
#Cell myCell[][]
def __init__(self, myW, myC):
self.myWall = myW
self.myCell = myC
def setdirection(self, a):
if ((a >= 0) & (a <= 3)):
self.direction = a
else:
self.direction = 0
print("self.direction is wrong!! self.direction is set to 0 (North).")
def getdirection(self):
return self.direction
def getX(self):
return self.x
def getY(self):
return self.y
def turnRight(self):
self.direction= self.direction + 1
if (self.direction > 3):
self.direction = 0
def turnLeft(self):
self.direction = self.direction -1
if (self.direction < 0):
self.direction = 3
def checkRight(self):
temp = False
if (self.direction == 0): # North
if (self.myWall[self.x + 1][self.y].getWall() == True): temp = True
else: temp = False
elif (self.direction == 1): # East
if (self.myWall[self.x][self.y + 1].getWall() == True): temp = True
else: temp = False
elif (self.direction == 2): # South
if (self.myWall[self.x - 1][self.y].getWall() == True): temp = True
else: temp = False
elif (self.direction == 3): # West
if (self.myWall[self.x ][self.y - 1].getWall() == True): temp = True
else: temp = False
return temp
def checkLeft(self):
temp = False
if (self.direction == 0): # North
if (self.myWall[self.x - 1][self.y].getWall() == True): temp = True
else: temp = False
elif (self.direction == 1): # East
if (self.myWall[self.x][self.y - 1].getWall() == True): temp = True
else: temp = False
elif (self.direction == 2): # South
if (self.myWall[self.x + 1][self.y].getWall() == True): temp = True
else: temp = False
elif (self.direction == 3): # West
if (self.myWall[self.x ][self.y + 1].getWall() == True): temp = True
else: temp = False
return temp
def checkFront(self):
temp = False
if (self.direction == 0): # North
if (self.myWall[self.x ][self.y - 1].getWall() == True): temp = True
else: temp = False
elif (self.direction == 1): # East
if (self.myWall[self.x + 1][self.y].getWall() == True): temp = True
else: temp = False
elif (self.direction == 2): # South
if (self.myWall[self.x][self.y + 1].getWall() == True): temp = True
else: temp = False
elif (self.direction == 3): # West
if (self.myWall[self.x - 1][self.y].getWall() == True): temp = True
else: temp = False
return temp
def Forward(self):
if (self.direction == 0): # North
self.y = self.y-1
elif (self.direction == 1): # East
self.x = self.x+1
elif (self.direction == 2): # South
self.y = self.y+1
elif (self.direction == 3): # West
self.x = self.x-1
self.markCell(self.x,self.y)
def markCell(self, x, y):
self.myWall[x][y].incrementMarked()