Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Variables
- $hp = $_REQUEST['hp_stat'];
- $def = $_REQUEST['def_stat'];
- $atk = $_REQUEST['atk_stat'];
- $mv = $_REQUEST['mv_power'];
- $ev1 = $_REQUEST['evs'];
- //This takes values of 1 and 0
- $def_nature = $_REQUEST['radio1'];
- //This takes values of 1 and 1.5
- $stab = $_REQUEST['radio2'];
- //Calculates the stats of the pokemon
- $hp = (131 + 2*$hp) +10;
- $def = (31 + 2*$def) + 5;
- $atk = (31 + 2*$atk) + 68;
- //Array with results
- $res1[5][4] = array();
- for ($c1 = 0; $c1 < 5; $c1++) {
- for ($c2 = 0; $c2 < 4; $c2++) {
- $res1[$c1][$c2] = $c1." - ".$c2;
- }
- }
- //Initialize it in 999
- $res1[0][0] = 999;
- //Gets min damage
- $min_dmg = calc($hp, $def, $atk, $mv, $stab);
- #HP / NO DEFENSE
- for ($cc = 4; $cc <= getLimit($ev1, $cc, 1); $cc += 4) {
- //Calculates damage
- $dmg = calc($hp+$cc/4, $def, $atk, $mv, $stab);
- //Gets result
- $num = getResult($dmg, $min_dmg, $cc, 0);
- if ($num <= $res1[0][0])
- $res1 = reorganizeArray($num, $cc, 0, "", $dmg, $res1);
- }
- #DEFENSE / NO HP
- for ($cc = 4; $cc <= getLimit($ev1, $cc, 1); $cc += 4) {
- //Calculates damage
- $dmg = calc($hp, $def+$cc/4, $atk, $mv, $stab);
- //Gets result
- $num = getResult($dmg, $min_dmg, 0, $cc);
- if ($num <= $res1[0][0])
- $res1 = reorganizeArray($num, 0, $cc, "", $dmg, $res1);
- }
- #HP / DEFENSE
- for ($c1 = 4; $c1 <= getLimit($ev1, $c1, 1); $c1 += 4) {
- for ($c2 = 0; $c2 <= getLimit($ev1, $c1, 2); $c2 +=4) {
- //Calculates damage
- $dmg = calc($hp+$c1/4, $def+$c2/4, $atk, $mv, $stab);
- //Gets result
- $num = getResult($dmg, $min_dmg, $c1, $c2);
- if ($num <= $res1[0][0])
- $res1 = reorganizeArray($num, $c1, $c2, "", $dmg, $res1);
- }
- }
- if ($def_nature == 1) {
- #DEFENSE + / NO HP
- for ($cc = 4; $cc <= getLimit($ev1, $cc, 1); $cc += 4) {
- //Calculates damage
- $dmg = calc($hp, ($def+$cc/4)*1.1, $atk, $mv, $stab);
- //Gets result
- $num = getResult($dmg, $min_dmg, 0, $cc);
- if ($num <= $res1[0][0])
- $res1 = reorganizeArray($num, 0, $cc, "+", $dmg, $res1);
- }
- #HP / DEFENSE +
- for ($c1 = 4; $c1 <= getLimit($ev1, $c1, 1); $c1 += 4) {
- for ($c2 = 0; $c2 <= getLimit($ev1, $c1, 2); $c2 +=4) {
- //Calculates damage
- $dmg = calc($hp+$c1/4, ($def+$c2/4)*1.1, $atk, $mv, $stab);
- //Gets result
- $num = getResult($dmg, $min_dmg, $c1, $c2);
- if ($num <= $res1[0][0])
- $res1 = reorganizeArray($num, $c1, $c2, "+", $dmg, $res1);
- }
- }
- }
- //Damage calc function
- function calc($hp_t, $def_t, $atk_t, $mv_t, $stab_t) {
- $dmg = ((((2 * 100 / 5 + 2) * $atk_t * $mv_t / $def_t) / 50) + 2) * $stab_t;
- $dmg /= $hp_t;
- $dmg *= 100;
- $dmg -= .1;
- return $dmg;
- }
- //Gets the limit for the cycles
- function getLimit($max, $current, $ans) {
- $dif = 0;
- if ($max > 252) {
- $dif = $max - $current;
- $max = 252;
- }
- else {
- $dif = $max - $current;
- }
- if ($dif > 252) {
- $dif = 252;
- }
- if ($ans == 1)
- return $max;
- else if ($ans == 2)
- return $dif;
- }
- //Gets the result
- function getResult($dmg, $min_dmg, $ev1, $ev2) {
- $dif = 0;
- $dif -= $dmg;
- $dif += $min_dmg;
- $ev_complete = $ev1 + $ev2;
- $ev_complete /= 252;
- $result = $dif + $ev_complete;
- $result /= $dif;
- $result = eqNum($result, ($ev1 + $ev2));
- //Makes a little bit of difference
- //People usually prefer HP > DEFENSE investment
- if ($ev1-48 > $ev2)
- $result *= .9935;
- return $result;
- }
- //Reorganizes the array with a NEW smaller number
- function reorganizeArray($newNumber, $newEV1, $newEV2, $sign, $newCalc, $res1) {
- $res2[4][4] = array();
- for ($c1 = 0; $c1 <= 4; $c1++) {
- for ($c2 = 0; $c2 < 4; $c2++) {
- $res2[$c1][$c2] = $res1[$c1][$c2];
- }
- }
- $res1[0][0] = $newNumber;
- $res1[0][1] = $newEV1;
- $res1[0][2] = $newEV2.$sign;
- $res1[0][3] = $newCalc;
- for ($c1 = 1; $c1 < 5; $c1++) {
- for ($c2 = 0; $c2 < 4; $c2++) {
- $res1[$c1][$c2] = $res2[$c1-1][$c2];
- }
- }
- return $res1;
- }
- //Prints the array with the results
- function printArray($array1) {
- for ($c1 = 0; $c1 < 5; $c1++) {
- //If the array is complete
- if ($array1[$c1][0] != 999) {
- echo "Result: ".$array1[$c1][0];
- echo "<br>";
- echo "HP EV's: ".$array1[$c1][1];
- echo "<br>";
- echo "Def EV's: ".$array1[$c1][2];
- echo "<br>";
- echo "Damage Taken: ".$array1[$c1][3]."%";
- echo "<br>";
- echo "-------------------------------------------------------------<br>";
- }
- else
- //Exit the cycle
- $c1 = 5;
- }
- }
- //Makes numbers kinda equal
- function eqNum($num, $evs){
- $a = 40000; // $a = 40000
- $h = 508; //$h = 460
- $k = 1; // $k = .8
- $num *= (($evs*$evs) + ($h*$h) - (2*$evs*$h) + (4*$a*$k))/(4*$a);
- return $num;
- }
- printArray($res1);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment