-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathant.py
54 lines (43 loc) · 1.25 KB
/
ant.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
import antType
ants = []
def getAnts():
return ants
class Ant:
def __init__(self, color, x, y):
self.x = x
self.y = y
self.type = antType.getAntTypeFromColor(color)
self.orientation = 0
global ants
ants += [self]
def getType(self):
return self.type
def getX(self):
return self.x
def getY(self):
return self.y
def getOrientation(self):
return self.orientation
def updateOrientation(self, direction):
"""
direction = 'G' or 'D'
"""
if direction == 'G':
self.orientation -= 90
elif direction == 'D':
self.orientation += 90
else:
print("Unknow direction !")
self.orientation %= 360
def walk(self, grid):
type = self.type
direction = antType.getBehaviorFromColor(type, grid.getValue(self.getX(), self.getY()))
self.updateOrientation(direction)
if self.orientation == 0:
self.y += 1
elif self.orientation == 90:
self.x += 1
elif self.orientation == 180:
self.y -= 1
elif self.orientation == 270:
self.x -= 1