Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active November 11, 2020 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/47d5730c4cc6d9e9dc031ec74a8d8f8b to your computer and use it in GitHub Desktop.
Save lbvf50mobile/47d5730c4cc6d9e9dc031ec74a8d8f8b to your computer and use it in GitHub Desktop.
Just PHP FUN 148.
<?php
# https://www.codewars.com/kata/536e9a7973130a06eb000e9f
function calculateDamage(string $yourType, string $opponentType, int $attack, int $defense): int
{
$x = 1;
$a = $yourType; $b = $opponentType;
if("fire" == $a){
if('fire' == $b) $x = 0.5;
if('grass' == $b) $x = 2;
if('water' == $b) $x = 0.5;
if('electric' == $b) $x = 1;
}
if("water" == $a){
if('fire' == $b) $x = 2;
if('grass' == $b) $x = 0.5;
if('water' == $b) $x = 0.5;
if('electric' == $b) $x = 0.5;
}
if("electric" == $a){
if('fire' == $b) $x = 1;
if('grass' == $b) $x =1;
if('water' == $b) $x = 2;
if('electric' == $b) $x = 0.5;
}
if("grass" == $a){
if('fire' == $b) $x = 0.5;
if('grass' == $b) $x = 0.5;
if('water' == $b) $x = 2;
if('electric' == $b) $x = 1;
}
return 50 * ($attack/$defense) * $x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment