0

The equation:

def defensefunction(attack, defense, damage):

     dmg_def = (damage/attack)*(attack - (defense - (attack * 0.5)))
     print(dmg_def)

The code above is written in python and works properly but in C# it's another story:

In C#:

public static double DefenseFunction(int attacker_damage, int attacker_attack, int defender_defense)

         double var1 = (attacker_damage/attacker_attack);
         double var2 = (attacker_attack- (defender_defense - (attacker_attack * 0.5)));
         double dmg_def = var1 * var2;
         return dmg_def;

There is a var1 and var2 because I tried to debug the code by splitting the equation.

What I found so far:

  • The equation in var 2 works properly (the value is equal to what i get on a Hand-Calculator).
  • var 1 could either be working right or not (most of the number should be from 0.1 to 0.9, To.String() rounded the number so just show a 0 on the form).
  • dmg_def gets printed as a 0 (It shouldn't be, for example: 0.8 * 173 != 0).

Things that maybe are relevant:

How the function gets called:

double dmg_from = Actor.DefenseFunction(_attacker.Damage, _attacker.Attack, _defender.Defense);

How i print the number on the form:

rtbMessages.Text += dmg_from.ToString() + Enviroment.NewLine;
JabbaWook
  • 677
  • 1
  • 8
  • 25
  • 2
    Your `attacker_damage` and `attacker_attack` parameters are defined as `int`s, which means `attacker_damage/attacker_attack` will do integer math, which is not what you want. That's just the first thing I saw... – adv12 Feb 16 '16 at 14:08
  • Ok, noted it. So i changed attacker_damage and attacker_attack to double and now is working properly, thank you :) – Luis Ramirez Feb 16 '16 at 14:23
  • Mods you can close this question now, and sorry for the duplicate i though that my problem had to do with other things. – Luis Ramirez Feb 16 '16 at 14:29
  • I think marking it as a duplicate closes it. So nothing more to do. – adv12 Feb 16 '16 at 14:31

0 Answers0