-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstrategy-basic.py
44 lines (35 loc) · 1.56 KB
/
strategy-basic.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
# Strategy Guide - Basic bot by ramk13
import rg
class Robot:
def act(self, game):
all_locs = {(x, y) for x in xrange(19) for y in xrange(19)}
spawn = {loc for loc in all_locs if 'spawn' in rg.loc_types(loc)}
obstacle = {loc for loc in all_locs if 'obstacle' in rg.loc_types(loc)}
team = {loc for loc in game.robots if game.robots[loc].player_id == self.player_id}
enemy = set(game.robots)-team
adjacent = set(rg.locs_around(self.location)) - obstacle
adjacent_enemy = adjacent & enemy
adjacent_enemy2 = {loc for loc in adjacent if (set(rg.locs_around(loc)) & enemy)} - team
safe = adjacent - adjacent_enemy - adjacent_enemy2 - spawn - team
def mindist(bots, loc):
return min(bots, key=lambda x: rg.dist(x, loc))
if enemy:
closest_enemy = mindist(enemy,self.location)
else:
closest_enemy = rg.CENTER_POINT
# we'll overwrite this if there's something better to do
move = ['guard']
if self.location in spawn:
if safe:
move = ['move', mindist(safe, rg.CENTER_POINT)]
elif adjacent_enemy:
if 9*len(adjacent_enemy) >= self.hp:
if safe:
move = ['move', mindist(safe, rg.CENTER_POINT)]
else:
move = ['attack', adjacent_enemy.pop()]
elif adjacent_enemy2:
move = ['attack', adjacent_enemy2.pop()]
elif safe:
move = ['move', mindist(safe, closest_enemy)]
return move