Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function sim_battle(lpack, rpack) that simulates the battle between lpack and rpack and returns the outcome of the battle. The rules and the mechanics

image text in transcribed

Write a function sim_battle(lpack, rpack) that simulates the battle between lpack and rpack and returns the outcome of the battle. The rules and the mechanics of the battle are exactly the same as described on the previous slide. The return value of this function should be in a form of a 2-tuple: A single-character string: "L" if lpack won, "R" if rpack won, or "T" if tied A list of the remaining dogs from the winning pack after the end of the battle. If the battle ended in a tie, then an empty list ([]) is used instead. For example, let's consider this function call: sim_battle([("normal", 6, 5), ("normal", 3, 4)], [("normal", 2, 2), ("normal", 3, 9)]). The first duel that would occur will be between ("normal", 6, 5) and ("normal", 2, 2) as they are pack leaders from lpack and rpack respectively. After a single attack, the left pack leader takes 2 damage, leaving 3 HP left, while the right pack leader takes 6 damage which would instantly bring its HP to -4. Thus, the right pack leader is knocked out which brings the end of the first duel. The second duel now will be between ("normal", 6, 3) and ("normal", 3, 9). Notice the health of the left pack leader has now been decreased to 3 due to the previous duel. This time the left pack leader is knocked out because the right pack leader's DP is enough to deal the final blow, down to exactly O HP (and at the same time, the right pack leader has taken 6 damage, leaving 3 HP remaining). Up next, we have ("normal", 3, 4) against ("normal", 3, 3). The winner of the duel will be the left leader pack with 1 HP left. With no more dogs to duel from the right pack, the left pack is declared the winner of the battle, and the function would need to return ('L', [("normal", 3, 1)]) You may assume lpack and rpack inputs are always valid, i.e. always lists of zero to five (inclusive) 3-tuple dogs. Your function will be tested using varying stats (HP and DP) values for each dog, so ensure that the function works properly with any given set of dogs. For this question, all breeds will be labelled "normal" i.e. no special battle effects. You may also assume that all lists and tuple inputs are well-formatted and valid according to the specification. 1 > >>> sim_battle([("normal", 6, 5), ("normal", 3, 4 2 ('l', [('normal', 3, 1)]) 3 >>> sim_battle([("normal", 10, 10)], [("normal", 4 ('R', [('normal', 5, 2)]) 5 >>> sim_battle([("normal", 10, 10)], [("normal", 6 ('I', []) 7 >>> sim_battle([], [("normal", 7, 7), ("normal", ('R', [('normal', 7, 7), ('normal', 3, 3), ('norr 9 >>> sim_battle([("normal", 2, 6), ("normal", 3, 4 10 [("normal", 5, 1), ("normal", 5, : 11 ('l', [('normal', 1, 2), ('normal', 1, 2)]) 8 Hint If you're feeling a bit overwhelmed or not sure where to begin, start with implementing a function that handles a simple duel (a fight between two dogs). Then, think about how you might make use of this helper function to simulate the whole battle

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago