Question

Bomb & Enemy Game @ python Generate 10*10 grids map, 33 walls(W), 33 paths(0), 33 enemies(E),...

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:

  1. 10*10 maps
  2. The value of eliminated enemies.
  3. The coordinate of 2 bombs.

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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)

Add a comment
Know the answer?
Add Answer to:
Bomb & Enemy Game @ python Generate 10*10 grids map, 33 walls(W), 33 paths(0), 33 enemies(E),...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT