-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyBot.py
More file actions
76 lines (63 loc) · 2.29 KB
/
MyBot.py
File metadata and controls
76 lines (63 loc) · 2.29 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import hlt
from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square
myID, game_map = hlt.get_init()
hlt.send_init("MyPythonBot")
def move_to_min(sq):
global game_map
minimo = 1000
sqrr = None
distancia = 1
if sq.strength < 10: # El cuadrado está vacío o es demasiado pequeño
return(Move(sq, STILL))
radio = int(min((game_map.width, game_map.height)) / 4)
while minimo == 1000 and distancia < radio :
vecinos = game_map.neighbors(sq, distancia)
for sqv in vecinos:
if sqv.owner != myID:
if sqv.strength < minimo:
minimo = sqv.strength
sqrr = sqv
distancia += 1
if minimo == 1000 : # cuadrado demasiado grande, hacemos crecer el centro hacia el vecino más pequeño
vecinos = game_map.neighbors(sq,3)
for sqv in vecinos:
if sqv.strength < minimo:
minimo = sqv.strength
sqrr = sqv
if sqrr.x < sq.x:
return(Move(sq,WEST))
if sqrr.x > sq.x:
return(Move(sq,EAST))
if sqrr.y < sq.y:
return(Move(sq,NORTH))
if sqrr.y > sq.y:
return(Move(sq,SOUTH))
while True:
game_map.get_frame()
moves = []
for square in game_map:
if square.owner == myID:
minimo = 1000
vecino_valido = False
sqrr = None
vecinos = game_map.neighbors(square, 1)
for sqv in vecinos:
if sqv.owner != myID:
vecino_valido = True
if sqv.strength < minimo and sqv.strength <= square.strength:
minimo = sqv.strength
sqrr = sqv
if vecino_valido and minimo == 1000:
moves.append(Move(square, STILL))
elif vecino_valido and minimo != 1000:
if sqrr.x < square.x:
moves.append(Move(square, WEST))
if sqrr.x > square.x:
moves.append(Move(square, EAST))
if sqrr.y < square.y:
moves.append(Move(square, NORTH))
if sqrr.y > square.y:
moves.append(Move(square, SOUTH))
else:
moves.append(move_to_min(square))
hlt.send_frame(moves)