-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbomb.py
101 lines (69 loc) · 4.72 KB
/
bomb.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from defs2 import in_range, get_possible_ways
from enemy import closer_enemies
def choose_hide_pos(bomberman_pos, bomb, mapa, previous_key, n, limit,enemies,detonador):
x,y = bomberman_pos
ord_enemies = closer_enemies(bomberman_pos, enemies)
if detonador:
raio = 2
else:
raio = 4
if not in_range(bomberman_pos, bomb[2], bomb[0], mapa) and not in_range(bomberman_pos,raio, ord_enemies[0][1], mapa):
return (bomberman_pos, True)
if n == limit:
if bomberman_pos != bomb[0]:
return (bomberman_pos, False)
else:
return (bomb[0], False)
ways = get_possible_ways(mapa, bomberman_pos)
if previous_key in ['a', 'd']: # andou para o lado, experimenta para o cima/baixo
if 'w' in ways and not in_range(mapa.calc_pos(bomberman_pos,'w'),1, ord_enemies[0][1], mapa):
return choose_hide_pos([x, y - 1], bomb, mapa, 'w', n + 1, limit,enemies,detonador)
if 's' in ways and not in_range(mapa.calc_pos(bomberman_pos,'s'),1, ord_enemies[0][1], mapa):
return choose_hide_pos([x,y+1], bomb, mapa, 's', n+1, limit,enemies,detonador)
if previous_key in ['w', 's']: # andou na vertical, experimenta para os lados
if 'a' in ways and not in_range(mapa.calc_pos(bomberman_pos, 'a'), 1, ord_enemies[0][1], mapa):
return choose_hide_pos([x - 1, y], bomb, mapa, 'a', n + 1, limit, enemies, detonador)
if 'd' in ways and not in_range(mapa.calc_pos(bomberman_pos,'d'),1, ord_enemies[0][1], mapa):
return choose_hide_pos([x + 1, y], bomb, mapa, 'd', n+1, limit,enemies,detonador)
if 'w' in ways and not in_range(mapa.calc_pos(bomberman_pos, 'w'), 1, ord_enemies[0][1], mapa):
return choose_hide_pos([x, y - 1], bomb, mapa, 'w', n + 1, limit, enemies, detonador)
if 's' in ways and not in_range(mapa.calc_pos(bomberman_pos, 's'), 1, ord_enemies[0][1], mapa):
return choose_hide_pos([x, y + 1], bomb, mapa, 's', n + 1, limit, enemies, detonador)
if 'a' in ways and not in_range(mapa.calc_pos(bomberman_pos, 'a'), 1, ord_enemies[0][1], mapa):
return choose_hide_pos([x - 1, y], bomb, mapa, 'a', n + 1, limit, enemies, detonador)
if 'd' in ways and not in_range(mapa.calc_pos(bomberman_pos,'d'),1, ord_enemies[0][1], mapa):
return choose_hide_pos([x + 1, y], bomb, mapa, 'd', n+1, limit,enemies,detonador)
else:
return bomberman_pos,False
def choose_hide_pos2(bomberman_pos, bomb, mapa, previous_key, n, limit,enemies,detonador):
x,y = bomberman_pos
ord_enemies = closer_enemies(bomberman_pos, enemies)
if detonador:
raio = 2
else:
raio = 4
if not in_range(bomberman_pos, bomb[2], bomb[0], mapa)and not in_range(bomberman_pos,raio, ord_enemies[0][1], mapa) :
return (bomberman_pos, True)
if n == limit:
return choose_hide_pos(bomberman_pos,bomb,mapa,'',0,70,enemies,detonador)
ways = get_possible_ways(mapa, bomberman_pos)
if previous_key in ['a', 'd']: # andou para o lado, experimenta para o cima/baixo
if 's' in ways and not in_range(mapa.calc_pos(bomberman_pos,'s'),1, ord_enemies[0][1], mapa):
return choose_hide_pos2([x,y+1], bomb, mapa, 's', n+1, limit,enemies,detonador)
if 'w' in ways and not in_range(mapa.calc_pos(bomberman_pos,'w'),1, ord_enemies[0][1], mapa):
return choose_hide_pos2([x, y - 1], bomb, mapa, 'w', n+1, limit,enemies,detonador)
if previous_key in ['w', 's']: # andou na vertical, experimenta para os lados
if 'd' in ways and not in_range(mapa.calc_pos(bomberman_pos, 'd'), 1, ord_enemies[0][1], mapa):
return choose_hide_pos2([x + 1, y], bomb, mapa, 'd', n + 1, limit, enemies, detonador)
if 'a' in ways and not in_range(mapa.calc_pos(bomberman_pos,'a'),1, ord_enemies[0][1], mapa):
return choose_hide_pos2([x-1,y], bomb, mapa, 'a', n+1, limit,enemies,detonador)
if 's' in ways and not in_range(mapa.calc_pos(bomberman_pos,'s'),1, ord_enemies[0][1], mapa):
return choose_hide_pos2([x, y + 1], bomb, mapa, 's', n+1, limit,enemies,detonador)
if 'w' in ways and not in_range(mapa.calc_pos(bomberman_pos,'w'),1, ord_enemies[0][1], mapa):
return choose_hide_pos2([x, y - 1], bomb, mapa, 'w', n+1, limit,enemies,detonador)
if 'd' in ways and not in_range(mapa.calc_pos(bomberman_pos, 'd'), 1, ord_enemies[0][1], mapa):
return choose_hide_pos2([x + 1, y], bomb, mapa, 'd', n + 1, limit, enemies, detonador)
if 'a' in ways and not in_range(mapa.calc_pos(bomberman_pos,'a'),1, ord_enemies[0][1], mapa):
return choose_hide_pos2([x-1,y], bomb, mapa, 'a', n+1, limit,enemies,detonador)
else:
return choose_hide_pos(bomb[0],bomb,mapa,previous_key,n+1,limit,enemies,detonador)