Bomb & Enemy Game @ python
Generate 10*10 grids map, 33 walls(W), 33 paths(0), 33 enemies(E), 1 bomber man(B)
The bomb can only be dropped on paths, bomber man cannot pass through the walls and enemies. Please make sure the bomber man can arrive at the paths and drop the bombs.
Bombs could eliminate the enemies which stand on the same rows and same columns. But the blast waves will stop when they hit on walls.
The bomber man needs to lay down 2 bombs, if the bombs eliminate the same enemy, it will count only once.
Final output:
Example:
00WW00WW00
0B00EEEWEE
0WW0WEWEWE
WE00E0WEEW
WEW0WW00WE
WEE0EEE0W0
WEW0WEW0WE
0WEE00E00E
0EW0WEWWW0
W00EEWEEE0
The first bomb's coordinate is: (2,4)
The second bomb's coordinate is: (6,4)
Total eliminated enemies: 10
I need the python code
import random
a=['W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','W','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','O','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','B']
random.shuffle(a)
for i in range(len(a)):
print(a[i],end='')
if (i+1)%10==0:
print('\n')
BAdd=a.index('B')
print(BAdd)
row_B=BAdd//10+1
col_B=BAdd%10+1
b=(row_B,col_B)
print('Bomber coordinate:',b)
w=[i for i, x in enumerate(a) if x =='W']
o=[i for i, x in enumerate(a) if x =='O']
e=[i for i, x in enumerate(a) if x =='E']
print(o)
if BAdd%10==0: s = [x for x in o if x == BAdd + 1 or x == BAdd - 10
or x == BAdd + 10]
print(s)
elif BAdd%10==9: s = [x for x in o if x == BAdd - 1 or x == BAdd -
10 or x == BAdd + 10]
print(s)
else: s =[x for x in o if x==BAdd-1 or x==BAdd+1 or x==BAdd-10 or
x==BAdd+10]
print(s)
if s is not None:
while len(s)<=33:
q=[x for x in o if x==[i+1 for i in s] or x==[i-1 for i in s] or
x==[i+10 for i in s] or x==[i-10 for i in s]]
s.append(q)
else:
print('Cannot drop the bomb!')
print(s)
print(q)
Bomb & Enemy Game @ python Generate 10*10 grids map, 33 walls(W), 33 paths(0), 33 enemies(E),...