Inlab: Composing Functions

For this inlab exercise we will focus on computing a useful statistic that describes the survivability of a character in the universe of Blizzard's very popular game Diablo III.

While you're probably familiar with the notion of a character's hit points (HP -- also sometimes called the "health pool"), which describes the amount of damage the character can take before dying, this value does very little to describe the myriad attributes of the character that help it survive monster attacks.

To better describe how much damage it really takes to "kill" a character, we prefer to compute something called the effective health pool (EHP), which takes into account various damage reducing variables.

Among the quantitites that factor into damage reduction are:

  1. Attributes intrinsic to a character such as vitality and dexterity -- the first increases the base HP of a character, and the second increases the character's dodge chance, which is a percentage likelihood that a monster trying to hit the character will miss.

  2. The amount of armor the character is wearing, which contributes to armor-based damage reduction.

  3. The amount of physical resistance the character is imbued with, which might come from magical items or spells. This contributes to resistance-based damage reduction.

  4. Intrinsic damage reduction, which is class specific.

  5. The "level" of a character (character level).

  6. The "level" of the monster attacking the character (monster level).

Computing EHP

Base HP

The base HP of a character with level lvl > 35 can be computed from his vitality vit using the following formula:

hp

When a character has level lvl ≤ 35, the following formula must be used:

hp

Armor-based damage reduction

The armor-based damage reduction when a monster of level mlvl attacks a character with armor value armor is computed as follows:

ar

Resistance-based damage reduction

The resistance-based damage reduction when a monster of level mlvl attacks a character with resistance value resist is computed as follows:

rr

Dodge chance

The percentage chance that a character can dodge a monster attack is purely based on the dexterity attribute, but the relationship is a bit complicated. It can be computed as follows:

Intrinsic damage reduction

For our purposes we will assume that the character under consideration is of a melee class, in which case the intrinsic damage reduction is a flat 30%.

Damage taken ratio

After coming up with a character's armor-based damage reduction (AR), resistance-based damage reduction (RR), dodge-chance (DC) and intrinsic damage reduction (IR) (all expressed as percentages), we can compute the damage-taken (DT) percentage as follows:

dt

EHP

Finally, after coming up with the damage-taken percentage, we can compute the character's effective health pool using its base HP as follows:

ehp

Note that this equation is fairly intuitive. If a character has a base HP of 100, but only takes half (50%) of each incoming attack, then it is as though the character has an effective HP of 100/0.5, or 200. Another way to interpret this result is that a monster attack that would normally cause 100 damage (thereby killing the character), only does 50 damage (50% damage taken).

Your implementation

You are to write a program that computes the EHP of a character given:

You should decompose the problem into a minimum of 6 functions. This template Racket source file contains a suggested breakdown, and also provides tests for implementations. (Please wait for us to complete our in-class discussion before looking at the file!)

You can also use this online EHP calculator to verify your results.