Exercise 3:
Q: Extend the benefit calculation to all card types. You may need to loop over all cards in a for
loop and do the benefit calculation differently for each type. Also, try to incorporate mechanics
like death damage and ranged attacks.
How close to 1 can you get the correlation?
A: For this exercise, our objective is to analyze the cost and benefit of each card type in order to
make sure all cards have approximately similar cost/benefit ratio and thus approximately similar
use rates. There are four main types of cards: troops, spells, buildings and tower troops.
1. Troops
A correlation of 1 would mean that the stat in question is directly proportional to cost. Correlation
of 0 indicates no relation, and negative correlations indicate inverse proportionality. Pandas
dataframe.corr() is used to find the pairwise correlation of all columns in the Pandas Dataframe
in Python. Initially, we can begin with the benefit calculation: benefit = health (+shield)
After this if we plot cost on the X axis and benefit on the Y axis, we get a correlation of: 0.6413
initially. We can improve this result by making the benefit calculation more realistic and true to
the game.
s["Benefit"]= s["Health (+Shield)"]
s.plot.scatter(x="Cost",y="Benefit")
print("Correlation:",s["Cost"].corr(s["Benefit"]))
We can diversify and possibly improve the result by introducing new variables such as count
and damage per second in the equation. And furthermore, other variables such as Range and
Spawn/ death damage can also be introduced.
s["Benefit"]=s["Count"]* s["Damage per Second"]* s["Health (+Shield)"]
We can add weights to all the variables to signify their importance compared to each other in the
equation For example:
Cost Benefit =w1 *Health+w2*Damage+w3*Hit Speed+w4*Damage per
Second+w5*Spawn/Death Damage+w6*Range+w7*Count
Adding the sum of these weights should be normalized to 1 to ensure that the overall correlation
is in the range [-1, 1]. We can start by giving each element an equal importance and then
adjusting the weights logically. So, for 5 variables the weight of each should be 0.2.
wCount = 0.15
wDPS = 0.2