-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaze.py
More file actions
60 lines (44 loc) · 1.07 KB
/
Copy pathmaze.py
File metadata and controls
60 lines (44 loc) · 1.07 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
import cellular
import random
import time
class Cell(cellular.Cell):
wall=False
trail=False
goal=False
def colour(self):
if self.wall: return 'black'
elif self.goal: return 'magenta'
elif self.trail: return 'green'
else: return 'white'
def load(self,text):
if text==' ':
self.wall=False
elif text=='G':
self.goal=True
elif text=='S':
self.world.addAgent(agent,cell=self)
else:
self.wall=True
class Agent(cellular.Agent):
colour='blue'
def update(self):
self.cell.trail=True
if self.leftCell.wall==False:
self.turnLeft()
self.goForward()
elif self.aheadCell.wall==False:
self.goForward()
elif self.rightCell.wall==False:
self.turnRight()
self.goForward()
else:
self.turnAround()
agent=Agent()
world=cellular.World(Cell,filename='maze1.txt',directions=4)
world.display.activate(size=5)
world.display.pause()
while 1:
world.update()
if agent.cell.goal==True:
world.display.pause()
break