-
Notifications
You must be signed in to change notification settings - Fork 3
/
simple_reflex_agent.py
63 lines (56 loc) · 2.47 KB
/
simple_reflex_agent.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
59
60
61
62
63
from directions import *
from states import *
from agent import *
class SimpleReflexAgent(Agent):
def __init__(self, startingPos, startingDir, environ):
super().__init__(startingPos, startingDir, environ)
self.AgentTypeName = "Simple Reflex Agent"
def Run(self):
running = True
if self.PrintMovements:
print("agent starting position: x:{} y:{}".format(self.Position[0],self.Position[1]))
print("agent starting direction: x:{} y:{}".format(self.DirFacingVec[0],self.DirFacingVec[1]))
while running:
self.GetPercept()
if self.Status == DIRTY:
self.CleanTile()
if self.FacingTile == DIRTY:
self.MoveForward()
else:
self.Rotate(CW) #45 deg
self.GetPercept()
if self.FacingTile == DIRTY:
self.MoveForward()
else:
self.Rotate(CW) #90 deg
self.GetPercept()
if self.FacingTile == DIRTY:
self.MoveForward()
else:
self.Rotate(CW) #135 deg
self.GetPercept()
if self.FacingTile == DIRTY:
self.MoveForward()
else:
self.Rotate(CW) #180 deg
self.GetPercept()
if self.FacingTile == DIRTY:
self.MoveForward()
else:
self.Rotate(CW) #225 deg
self.GetPercept()
if self.FacingTile == DIRTY:
self.MoveForward()
else:
self.Rotate(CW) #270 deg
self.GetPercept()
if self.FacingTile == DIRTY:
self.MoveForward()
else:
self.Rotate(CW) #315 deg
self.GetPercept()
if self.FacingTile == DIRTY:
self.MoveForward()
else:
running = False
return