Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. In the board game Risk, a player attacks by rolling either 1,2 or 3 dice. The player defending rolls either 1 or 2 dice

3. In the board game Risk, a player attacks by rolling either 1,2 or 3 dice. The player defending rolls either 1 or 2 dice (but never more dice than the attacker). The maximum die of each is compared, if the attackers roll is greater than the defenders roll, then the defender loses 1 army, if the defender is greater or the dice are equal, the attacker loses 1 army. Then, if the defender rolled two dice, the same calculation is repeated for the 2nd highest die of each player. For example, if the attacker rolls [1,5,3] and the defender rolls [3,3], then the defender loses 1 (because 3<5) and the attacker loses 1 (because the defender wins on the tie 3==3). Implement a function result, which when given the rolls of the attacker and then the defender, returns a tuple (attacker loss, defender loss). Hint: it may help to sort!

>>> result( [1,4,5], [3,2] )

(0, -2)

>>> result( [1,6,5], [5,5] )

(-1, -1)

>>> result( [1,6,5], [3,2] )

(0, -2)

>>> random.seed(0)

>>> result( rollDice(3), rollDice(2) )

(-1, -1)

>>> result( rollDice(3), rollDice(2) )

(-1, -1)

>>> result( rollDice(3), rollDice(2) )

(0, -2)

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

(a) What is the mode?

Answered: 1 week ago

Question

5. Describe the visual representations, or models, of communication

Answered: 1 week ago