Question: class Monster(): def __init__(self, name, hp=20): self.exp = 0 self.attacks = {'wait': 0} self.name = name self.known_attacks = {'sneak_attack': 1, 'slash': 2, 'ice_storm': 3, 'fire_storm':

 class Monster(): def __init__(self, name, hp=20): self.exp = 0 self.attacks ={'wait': 0} self.name = name self.known_attacks = {'sneak_attack': 1, 'slash': 2, 'ice_storm':

class Monster(): def __init__(self, name, hp=20): self.exp = 0 self.attacks = {'wait': 0} self.name = name self.known_attacks = {'sneak_attack': 1, 'slash': 2, 'ice_storm': 3, 'fire_storm': 3, 'whirlwind': 3, 'earthquake': 2, 'double_hit': 4, 'wait': 0} self.current_hp = hp self.max_hp = hp self.type = 'normal'

def add_attack(self, attack_name): if attack_name in self.known_attacks and attack_name not in self.attacks: try: assert(len(self.attacks)

def remove_attack(self, attack_name): if attack_name in self.attacks.keys(): del self.attacks[attack_name] if len(self.attacks) == 0: self.attacks['wait'] = 0 return True else: return False

def win_fight(self): self.exp+=5 self.current_hp = self.max_hp

def lose_fight(self): self.exp+=1 self.current_hp = self.max_hp

class Dragon(Monster):

def __init__(self, name, hp=20): super().__init__(name, hp) self.type = 'dragon' self.counter = 10

def win_fight(self): self.exp+=5 self.current_hp = self.max_hp if self.exp >= self.counter: self.counter += 10 for key in self.attacks: self.attacks[key] = self.attacks.get(key) + 1

def lose_fight(self): self.exp += 1 self.current_hp = self.max_hp

class Ghost(Monster):

def __init__(self, name, hp=20): super().__init__(name, hp) self.type = 'ghost' self.counter = 10

def win_fight(self): self.exp+=5 self.current_hp = self.max_hp if self.exp >= self.counter: self.counter += 10 self.max_hp = self.max_hp + 5 self.current_hp = self.max_hp

def lose_fight(self): self.exp += 1 self.current_hp = self.max_hp

def monster_fight(monster1, monster2):

M1round = 0 M2round = 0 monster2attackLis = [] monster1attackLis = [] winner = None round = 0

for values in monster2.attacks.values(): monster2attackLis.append(values) for values in monster1.attacks.values(): monster1attackLis.append(values)

monster2attackLis = sorted(monster2attackLis, reverse=True) monster1attackLis = sorted(monster1attackLis, reverse=True) #-----------------------------------------#

M1attacknames = sorted(monster1.attacks.items(), key=operator.itemgetter(1), reverse=True) M2attacknames = sorted(monster2.attacks.items(), key=operator.itemgetter(1), reverse=True)

winnerList = [] #list of the winners moves

index1 = 0 index2 = 0

if all(key == 'wait' for key in monster1.attacks.keys()) and all(key == 'wait' for key in monster1.attacks.keys()): return (-1, None, None)

while(monster2.current_hp > 0):

try: monster2.current_hp -= monster1attackLis[index1] index1 += 1 M1round += 1

except IndexError:

index1 = 0

while(monster1.current_hp > 0):

try: monster1.current_hp -= monster2attackLis[index2] index2 += 1 M2round += 1

except IndexError:

index2 = 0

if(M1round == M2round): winner = monster1 round = M1round monster1.win_fight() monster2.lose_fight() index = 0 i = 0 while i

elif(M1round

elif(M2round

return (round, winner, winnerList)

OR

class Monster(): # Initializing the Monster object with default values def __init__(self, name, hp=20): self.max_hp = hp self.exp = 0 self.name = name self.hp = hp self.attacks = {"fire_storm":3,"ice_storm":3,"earthquake":2,"double_hit":4} self.performed_attacks = [] # add_attack method adds the performed attack to the list def add_attack(self, attack_name): self.performed_attacks.append(attack_name) # when opposite monster perform the attack, removes the hp from this object def remove_attack(self, attack_name): self.hp = self.hp - self.attacks[attack_name] # when the winner is this monster then add 5 exp and setting hp to max def win_fight(self): self.hp = self.max_hp self.exp = self.exp + 5 # when the loser is this monster then add 1 exp and setting hp to max def lose_fight(self): self.hp = self.max_hp self.exp = self.exp + 1 def monster_fight(monster1, monster2): attacks = ["double_hit","fire_storm","ice_storm","earthquake"] i=0 round = 0 pa1 = [] pa2 = [] while(monster1.hp>=0 and monster2.hp>=0): if(i%2==0): monster1.add_attack(attacks[i//2]) pa1.append(attacks[i//2]) monster2.remove_attack(attacks[i//2]) i = i + 1 else: monster2.add_attack(attacks[i//2]) pa2.append(attacks[i//2]) monster1.remove_attack(attacks[i//2]) i = i + 1 if(i == 8): round = round + 1 i = 0 if(monster1.hp 

PLEASE HELP ME CORRECT ONE OR BOTH OF THESE CODES FOR THIS PROBLEM.

13.12 PA4 Q2: Fight! Now we want a way to make our monsters fight! Before two monsters can fight, we need to give 2 new class methods that update their stats. Implement a method for "win_fight" and "lose_fight". Win_fight should add 5 to the monster's self.exp and reset their hp to max_hp. "lose_fight" should also reset their hp but only adds 1 exp to self.exp. Now write a function that takes 2 instances of the monster class and makes them fight. This function should be defined outside the Monster class, i.e. it is not a Monster method. A fight goes as follows: 1. The monster that entered as the first function goes first. 2. Each monster takes a turn using one attack move. The monster selects this attack move from the strongest to the weakest in a circular function. For example: A monster has a dictionary of possible attack as follows: ["fire_storm": 3, "double_hit": 4, "earthquake": 2, "ice_storm": 3] Monster will select the following attacks: Round No Move Explanation 1 double_hit Highest hit points 2 fire_storm Same hit points as ice_storm but comes first alphabetically 3 ice_storm 4 earthquake 5 double_hit 6 fire_storm 7 ice_storm .... And so on. 3. An attack is always successful and will decrease the opponent's hp by the given number of points in self.attacks dictionary. The monsters continue taking turns until their current hp becomes less than or equal to zero. 4. At this point, the win_fight and lose_fight method should be invoked. Once this complete, return 3 things from the function. o Round_number Monster that won (return the corresponding Monster object) o List of attacks the monster used Special Edge Case: If both monster only have "wait" as an attack, return . -1 (round_number) None (for monster name that won) None (for list of attack that monster use) 2996721716238.qx3zqy7 LAB ACTIVITY 13.12.1: PA4 Q2: Fight! 0/30 main.py Load default template... 1 class Monster(): 2 def __init__(self, name, hp=20): Self.exp = 0 4 #your code here def add_attack(self, attack_name): 6 pass #your code here 7 def remove_attack(self, attack_name): 8 pass #your code here 9 def win_fight (self): 19 pass #your code here 11 def lose_fight (self): 12 pass #your code here 13 14 def monster_fight (monsteri, monster): 15 pass #your code here 16 Develop mode Submit mode When done developing your program, press the Submit for grading button below. This will submit your program for auto-grading

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!