forked from phreeza/cells
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mind1.py
44 lines (38 loc) · 1.61 KB
/
mind1.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
import random,cells
class AgentMind:
def __init__(self):
self.my_plant = None
self.mode = 1
self.target_range = random.randrange(50,1000)
pass
def act(self,view,msg):
x_sum = 0
y_sum = 0
dir = 1
n = len(view.get_plants())
mp = (mx,my)=view.get_me().get_pos()
me = view.get_me()
for a in view.get_agents():
if (a.get_team()!=me.get_team()):
return cells.Action(cells.ActionType.ATTACK,a.get_pos())
if(n>0):
if (not self.my_plant):
self.my_plant = view.get_plants()[0]
elif self.my_plant.get_eff()<view.get_plants()[0].get_eff():
self.my_plant = view.get_plants()[0]
if (((view.get_me().get_energy() < self.target_range) and (view.get_energy().get(mp) > 0))
or (view.get_energy().get(mp) > 100)) :
return cells.Action(cells.ActionType.EAT)
if self.my_plant:
dist = max(abs(mx-self.my_plant.get_pos()[0]),abs(my-self.my_plant.get_pos()[1]))
if (not view.get_me().is_loaded()) and (dist < 5) and (random.random()>0.5):
return cells.Action(cells.ActionType.LIFT)
if (view.get_me().is_loaded()) and dist > 5:
return cells.Action(cells.ActionType.DROP)
if view.get_me().get_energy() < dist*1.5:
(mx,my) = self.my_plant.get_pos()
return cells.Action(cells.ActionType.MOVE,(mx+random.randrange(-1,2),my+random.randrange(-1,2)))
if (random.random()>0.9):
return cells.Action(cells.ActionType.SPAWN,(mx+random.randrange(-1,2),my+random.randrange(-1,2)))
else:
return cells.Action(cells.ActionType.MOVE,(mx+random.randrange(-1,2),my+random.randrange(-1,2)))