forked from phreeza/cells
-
Notifications
You must be signed in to change notification settings - Fork 1
/
agent.py
50 lines (42 loc) · 1.41 KB
/
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
from constants import ATTACK_POWER, ATTACK_TERR_CHANGE, TEAM_COLORS_FAST
class Agent(object):
__slots__ = ['x', 'y', 'mind', 'energy', 'alive', 'team', 'loaded', 'color',
'act']
def __init__(self, x, y, energy, team, AgentMind, cargs):
self.x = x
self.y = y
self.mind = AgentMind(cargs)
self.energy = energy
self.alive = True
self.team = team
self.loaded = False
self.color = TEAM_COLORS_FAST[team % len(TEAM_COLORS_FAST)]
self.act = self.mind.act
def __str__(self):
return "Agent from team %i, energy %i" % (self.team,self.energy)
def attack(self, other, offset = 0, contested = False):
if not other:
return False
max_power = ATTACK_POWER + ATTACK_TERR_CHANGE * offset
if contested:
other.energy -= min(self.energy, max_power)
else:
other.energy -= max_power
return other.energy <= 0
def get_team(self):
return self.team
def get_pos(self):
return (self.x, self.y)
def set_pos(self, x, y):
self.x = x
self.y = y
def get_view(self):
return AgentView(self)
class AgentView(object):
def __init__(self, agent):
(self.x, self.y) = agent.get_pos()
self.team = agent.get_team()
def get_pos(self):
return (self.x, self.y)
def get_team(self):
return self.team