-
Notifications
You must be signed in to change notification settings - Fork 0
/
hunter_bot.py
48 lines (46 loc) · 1.58 KB
/
hunter_bot.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
import math
import random
from player import Player
class HunterBot(Player):
def do_turn(self, m):
orders = []
my_ants = [a for a in m.ants if a.owner == 1]
for ant in my_ants:
if ant.owner != 1:
continue
x, y = ant.x, ant.y
candidates = [
(x, y, x + 1, y),
(x, y, x - 1, y),
(x, y, x, y + 1),
(x, y, x, y - 1)
]
closest_enemy = None
closest_distance = 999999.0
for other_ant in m.ants:
if other_ant.owner == 1:
continue
dx = ant.x - other_ant.x
dy = ant.y - other_ant.y
dist = math.sqrt(dx ** 2 + dy ** 2)
if dist < closest_distance:
closest_distance = dist
closest_enemy = other_ant
best_move = None
closest_distance = 999999.0
for c in candidates:
if c[2] < 0 or c[3] < 0:
continue
if c[2] >= m.width or c[3] >= m.height:
continue
if not m.passable[c[2]][c[3]]:
continue
dx = c[2] - closest_enemy.x
dy = c[3] - closest_enemy.y
dist = math.sqrt(dx ** 2 + dy ** 2)
if dist < closest_distance:
closest_distance = dist
best_move = c
if best_move is not None:
orders.append(best_move)
return orders