I am writing simple drop formula for player A vs. B fights – level difference determinates drop rate. My issue here is that instead of 0: > 10 ||| 1 vs. 1 = 10% it gives 0: > 10 ||| 1 vs. 1 = 0% – why?
PhpFiddle: http://www.phpfiddle.org/main/code/n1q-dw7
<?php
# lets simulate high level player A attacks low level player B
for ($A = 1; $A <= 100; $A++) {
$B = 1;
calculateMoneyDrop($A,$B);
}
# lets simulate low level player A attacks high level player B
for ($B = 1; $B <= 100; $B++) {
$A = 1;
calculateMoneyDrop($A,$B);
}
function calculateMoneyDrop($A,$B) {
$X = $A - $B;
echo '<strong>', $X, '</strong>: ';
switch ($X) {
case $X > 10:
echo "> 10 ||| ";
$X = 10;
break;
case $X < -90:
echo "< -90 ||| ";
$X = -90;
break;
}
$dropRate = 10 - $X;
echo $A, ' vs. ', $B, ' = ', $dropRate, '%<br>';
}
Well, in your
$X > 10case you set$X = 10and later calculate$dropRateas10 - $X, which is10 - 10, which is0.Either the
$dropRateshould be$Xif the desired outcome is10. It also strikes me funny that the output says$X == 0first, but then enters the switch case$X > 10… Are you sure that you’re showing us all the code?Also I don’t think it’s good practice to use the
switchcase like that. This is a typical candidate for anifblock.