Created
September 27, 2014 01:04
-
-
Save viphat/7518523c39d07365b1b7 to your computer and use it in GitHub Desktop.
Pokemon Damage Calculator
Kata on Codewars - http://www.codewars.com/kata/536e9a7973130a06eb000e9f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculateDamage(yourType, opponentType, attack, defense){ | |
var type = { | |
fire:0, | |
water:1, | |
grass:2, | |
electric:3 | |
}; | |
var effectivenessTable = [[0.5,0.5,2,1],[2,0.5,0.5,0.5],[0.5,2,0.5,1],[1,2,1,0.5]]; | |
var effectiveness = effectivenessTable[type[yourType]][type[opponentType]]; | |
return Math.ceil(50 * (attack/defense) * effectiveness); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var effects = { | |
fire : { | |
fire : 0.5, | |
grass : 2, | |
water : 0.5, | |
electric : 1 | |
}, | |
grass : { | |
fire : 0.5, | |
grass : 0.5, | |
water : 2, | |
electric : 1 | |
}, | |
water : { | |
fire : 2, | |
grass : 0.5, | |
water : 0.5, | |
electric : 0.5 | |
}, | |
electric : { | |
fire : 1, | |
grass : 1, | |
water : 2, | |
electric : 0.5 | |
} | |
}; | |
function calculateDamage(yourType, opponentType, attack, defense){ | |
return Math.ceil(50 * (attack/defense) * effects[yourType][opponentType]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment