Temporelucis

Pokemon EV's Optimizer

Apr 11th, 2015
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.78 KB | None | 0 0
  1. <?php
  2.     //Variables
  3.     $hp = $_REQUEST['hp_stat'];
  4.     $def = $_REQUEST['def_stat'];
  5.     $atk = $_REQUEST['atk_stat'];
  6.     $mv = $_REQUEST['mv_power'];
  7.     $ev1 = $_REQUEST['evs'];
  8.    
  9.     //This takes values of 1 and 0 
  10.     $def_nature = $_REQUEST['radio1'];
  11.  
  12.     //This takes values of 1 and 1.5
  13.     $stab = $_REQUEST['radio2'];
  14.  
  15.     //Calculates the stats of the pokemon
  16.     $hp = (131 + 2*$hp) +10;
  17.     $def = (31 + 2*$def) + 5;
  18.     $atk = (31 + 2*$atk) + 68;
  19.  
  20.     //Array with results
  21.     $res1[5][4] = array();
  22.  
  23.     for ($c1 = 0; $c1 < 5; $c1++) {
  24.         for ($c2 = 0; $c2 < 4; $c2++) {
  25.             $res1[$c1][$c2] = $c1." - ".$c2;
  26.         }
  27.     }
  28.  
  29.     //Initialize it in 999
  30.     $res1[0][0] = 999;
  31.  
  32.     //Gets min damage
  33.     $min_dmg = calc($hp, $def, $atk, $mv, $stab);
  34.  
  35.     #HP / NO DEFENSE
  36.     for ($cc = 4; $cc <= getLimit($ev1, $cc, 1); $cc += 4) {
  37.         //Calculates damage
  38.         $dmg = calc($hp+$cc/4, $def, $atk, $mv, $stab);
  39.         //Gets result
  40.         $num = getResult($dmg, $min_dmg, $cc, 0);
  41.         if ($num <= $res1[0][0])
  42.             $res1 = reorganizeArray($num, $cc, 0, "", $dmg, $res1);
  43.  
  44.     }
  45.  
  46.     #DEFENSE / NO HP
  47.     for ($cc = 4; $cc <= getLimit($ev1, $cc, 1); $cc += 4) {
  48.         //Calculates damage
  49.         $dmg = calc($hp, $def+$cc/4, $atk, $mv, $stab);
  50.         //Gets result
  51.         $num = getResult($dmg, $min_dmg, 0, $cc);
  52.         if ($num <= $res1[0][0])
  53.             $res1 = reorganizeArray($num, 0, $cc, "", $dmg, $res1);
  54.  
  55.     }
  56.  
  57.     #HP / DEFENSE
  58.     for ($c1 = 4; $c1 <= getLimit($ev1, $c1, 1); $c1 += 4) {
  59.         for ($c2 = 0; $c2 <= getLimit($ev1, $c1, 2); $c2 +=4) {
  60.             //Calculates damage
  61.             $dmg = calc($hp+$c1/4, $def+$c2/4, $atk, $mv, $stab);
  62.             //Gets result
  63.             $num = getResult($dmg, $min_dmg, $c1, $c2);
  64.             if ($num <= $res1[0][0])
  65.                 $res1 = reorganizeArray($num, $c1, $c2, "", $dmg, $res1);
  66.         }
  67.     }
  68.  
  69.     if ($def_nature == 1) {
  70.         #DEFENSE + / NO HP
  71.         for ($cc = 4; $cc <= getLimit($ev1, $cc, 1); $cc += 4) {
  72.             //Calculates damage
  73.             $dmg = calc($hp, ($def+$cc/4)*1.1, $atk, $mv, $stab);
  74.             //Gets result
  75.             $num = getResult($dmg, $min_dmg, 0, $cc);
  76.             if ($num <= $res1[0][0])
  77.                 $res1 = reorganizeArray($num, 0, $cc, "+", $dmg, $res1);
  78.  
  79.         }
  80.  
  81.         #HP / DEFENSE +
  82.         for ($c1 = 4; $c1 <= getLimit($ev1, $c1, 1); $c1 += 4) {
  83.             for ($c2 = 0; $c2 <= getLimit($ev1, $c1, 2); $c2 +=4) {
  84.                 //Calculates damage
  85.                 $dmg = calc($hp+$c1/4, ($def+$c2/4)*1.1, $atk, $mv, $stab);
  86.                 //Gets result
  87.                 $num = getResult($dmg, $min_dmg, $c1, $c2);
  88.                 if ($num <= $res1[0][0])
  89.                     $res1 = reorganizeArray($num, $c1, $c2, "+", $dmg, $res1);
  90.             }
  91.         }
  92.  
  93.     }
  94.  
  95.     //Damage calc function
  96.     function calc($hp_t, $def_t, $atk_t, $mv_t, $stab_t) {
  97.         $dmg = ((((2 * 100 / 5 + 2) * $atk_t * $mv_t / $def_t) / 50) + 2) * $stab_t;
  98.         $dmg /= $hp_t;
  99.         $dmg *= 100;
  100.         $dmg -= .1;
  101.         return $dmg;
  102.     }
  103.  
  104.     //Gets the limit for the cycles
  105.     function getLimit($max, $current, $ans) {
  106.         $dif = 0;
  107.  
  108.         if ($max > 252) {
  109.             $dif = $max - $current;
  110.             $max = 252;
  111.         }
  112.         else {
  113.             $dif = $max - $current;
  114.         }
  115.  
  116.         if ($dif > 252) {
  117.             $dif = 252;
  118.         }
  119.  
  120.         if ($ans == 1)
  121.             return $max;
  122.         else if ($ans == 2)
  123.             return $dif;
  124.  
  125.     }
  126.  
  127.     //Gets the result
  128.     function getResult($dmg, $min_dmg, $ev1, $ev2) {
  129.         $dif = 0;
  130.         $dif -= $dmg;
  131.         $dif += $min_dmg;
  132.  
  133.         $ev_complete = $ev1 + $ev2;
  134.         $ev_complete /= 252;
  135.  
  136.         $result = $dif + $ev_complete;
  137.         $result /= $dif;
  138.         $result = eqNum($result, ($ev1 + $ev2));
  139.        
  140.         //Makes  a little bit of difference
  141.         //People usually prefer HP > DEFENSE investment
  142.         if ($ev1-48 > $ev2)
  143.                     $result *= .9935;
  144.  
  145.         return $result;
  146.     }
  147.  
  148.     //Reorganizes the array with a NEW smaller number
  149.     function reorganizeArray($newNumber, $newEV1, $newEV2, $sign, $newCalc, $res1) {
  150.        
  151.         $res2[4][4] = array();
  152.  
  153.         for ($c1 = 0; $c1 <= 4; $c1++) {
  154.             for ($c2 = 0; $c2 < 4; $c2++) {
  155.                 $res2[$c1][$c2] = $res1[$c1][$c2];
  156.             }
  157.         }
  158.  
  159.         $res1[0][0] = $newNumber;
  160.         $res1[0][1] = $newEV1;
  161.         $res1[0][2] = $newEV2.$sign;
  162.         $res1[0][3] = $newCalc;
  163.  
  164.         for ($c1 = 1; $c1 < 5; $c1++) {
  165.             for ($c2 = 0; $c2 < 4; $c2++) {
  166.                 $res1[$c1][$c2] = $res2[$c1-1][$c2];
  167.             }
  168.         }
  169.  
  170.         return $res1;
  171.     }
  172.  
  173.     //Prints the array with the results
  174.     function printArray($array1) {
  175.         for ($c1 = 0; $c1 < 5; $c1++) {
  176.             //If the array is complete
  177.             if ($array1[$c1][0] != 999) {
  178.                     echo "Result: ".$array1[$c1][0];
  179.                     echo "<br>";
  180.                     echo "HP EV's: ".$array1[$c1][1];
  181.                     echo "<br>";
  182.                     echo "Def EV's: ".$array1[$c1][2];
  183.                     echo "<br>";
  184.                     echo "Damage Taken: ".$array1[$c1][3]."%";
  185.                     echo "<br>";
  186.                 echo "-------------------------------------------------------------<br>";
  187.             }
  188.             else
  189.                 //Exit the cycle
  190.                 $c1 = 5;
  191.         }      
  192.     }
  193.  
  194.     //Makes numbers kinda equal
  195.     function eqNum($num, $evs){
  196.         $a = 40000; // $a = 40000
  197.         $h = 508; //$h = 460
  198.         $k = 1; // $k  = .8
  199.  
  200.         $num *= (($evs*$evs) + ($h*$h) - (2*$evs*$h) + (4*$a*$k))/(4*$a);
  201.         return $num;
  202.     }
  203.  
  204.     printArray($res1);
  205. ?>
Advertisement
Add Comment
Please, Sign In to add comment