Ejemplo n.º 1
0
 protected function createMotionModule(SnakePlayer $player, $direction)
 {
     $head = $player->getHead();
     $module = new \stdClass();
     $direction = $this->calcDirection($direction, $head->d);
     switch ($direction) {
         case "l":
             $module->x = $head->x + minus(self::distance);
             $module->y = $head->y;
             break;
         case "r":
             $module->x = $head->x + self::distance;
             $module->y = $head->y;
             break;
         case "u":
             $module->y = $head->y + minus(self::distance);
             $module->x = $head->x;
             break;
         case "d":
             $module->y = $head->y + self::distance;
             $module->x = $head->x;
             break;
     }
     $module->d = $direction;
     return $module;
 }
Ejemplo n.º 2
0
 function normSquare($a, $b)
 {
     if (!is_array($a) || !is_array($b) || count($a) != count($b)) {
         return array();
     }
     $result = 0;
     $diff = minus($a, $b);
     foreach ($diff as $key => $value) {
         $result += abs($value * $value);
     }
     return sqrt($result) / count($diff);
 }
Ejemplo n.º 3
0
function calc($num, $string)
{
    switch ($string) {
        case '+':
            echo "Summ = " . array_sum($num);
            break;
        case '-':
            echo "difference = " . minus($num);
            break;
        case '*':
            echo "multiplication = " . array_product($num);
            break;
        case '/':
            echo "quotient = " . devide($num);
            break;
        default:
            echo 'Try another action: +, -, *, /';
    }
}
Ejemplo n.º 4
0
function ymnoj($pole, $pole1)
{
    return $pole * $pole1;
}
echo <<<END
<form name="" method="POST" action="">
   <input type="text" name="pole">
   <button type="submit" name="btn" value="+">+</button>
   <button type="submit" name="btn" value="-">-</button>
   <button type="submit" name="btn" value="/">/</button>
   <button type="submit" name="btn" value="*">*</button>
   <input type="text" name="pole1"> 
 </form>
END;
switch ($btn) {
    case '+':
        echo '= ' . plus($pole, $pole1);
        break;
    case '-':
        echo '= ' . minus($pole, $pole1);
        break;
    case '/':
        echo '= ' . del($pole, $pole1);
        break;
    case '*':
        echo '= ' . ymnoj($pole, $pole1);
        break;
    default:
        echo "Вводите числа!";
        break;
}
Ejemplo n.º 5
0
 public function getBPByPropByCalc($prop = array())
 {
     $this->load->helper('vector');
     $invTnt = array();
     //注意!invTnt[0-4]*[hmade]^-1 = 100000 *[xgfmm]!!!! BP是100000倍,而random表是100倍。
     $invTnt[] = array(13.24901855, -0.806318907, -6.785929774, -10.93898148, -16.40847223);
     $invTnt[] = array(-0.782811067, -0.608853052, 38.607709, -2.429143453, -3.643715179);
     $invTnt[] = array(-0.69583206, -0.541202713, -2.719073478, 34.87779841, -3.238857937);
     $invTnt[] = array(-0.467806013, -0.363849121, -2.954151876, -2.452651293, 51.87657862);
     $invTnt[] = array(-0.935612027, 10.38341287, -5.908303753, -4.905302585, -7.357953878);
     $result = array();
     $prop = minus($prop, mul(1, array(20, 20, 20, 20, 20)));
     for ($i = 0; $i < 5; $i++) {
         $result[$i] = 0;
         for ($j = 0; $j < 5; $j++) {
             $result[$i] += $invTnt[$i][$j] * $prop[$j] / 100;
         }
     }
     return $result;
 }
Ejemplo n.º 6
0
 public function test()
 {
     echo '<pre>';
     echo '<meta charset = utf8>';
     $this->load->helper('vector');
     $pets = array();
     /*
     $pets[] = '1947 2899 270 254 184 93 星菇 0 mo 242 158::lv93 00002 162 52 40 52 242';
     $pets[] = '309 230 110 59 46 10 改造僵尸 0 gong 加攻';
     $pets[] = '430 254 138 84 71 17 改造猎豹 16 no 00321  17级未加';
     $pets[] = '235 300 55 113 44 10 潜盾 9 no 未加1D 1血';
     $pets[] = '553 461 219 153 118 32 螳螂 31 no';
     $pets[] = '391 327 158 113 88 21 螳螂 20 no';
     $pets[] = '244 206 103 76 61 11 螳螂 10 no';
     */
     //$pets[] = '156 133 70 53 44 5 螳螂 4 no';
     //$pets[] = '97 85 47 39 34 1 螳螂 0 no';
     $pets[] = '640 409 286 138 99 29 改造烈风哥布林 0 gong';
     foreach ($pets as $pet) {
         echo $pet;
         echo '<br>';
         $petData = explode(' ', $pet);
         $grade = $this->pet_model->getGradesBySearch($petData[6]);
         $prop = array($petData[0], $petData[1], $petData[2], $petData[3], $petData[4]);
         $lv = $petData[5];
         $rBP = $petData[7];
         $addBPMethod = $petData[8];
         $addBP = $this->pet_model->getAddBPByCond($lv, $addBPMethod, $rBP);
         if (!$addBP) {
             echo '加点不合法!';
             continue;
         }
         $bp = $this->pet_model->getBPByProp($prop);
         $bprange = $this->pet_model->getBPRangeByProp($prop);
         $bpsql2min = minus($bprange[0], $addBP);
         $bpsql2max = minus($bprange[1], $addBP);
         $grade = array('xue' => $grade[0]->xue, 'gong' => $grade[0]->gong, 'fang' => $grade[0]->fang, 'min' => $grade[0]->min, 'mo' => $grade[0]->mo);
         //echo implode('/', $grade).'<br>';
         $maxdg = array();
         $mindg = array();
         foreach ($bpsql2max as $key => $value) {
             $tmp = $value / (($lv - 1) * 0.04 + 0.2);
             //$tmp = ($value/(($lv-1)*$this->pet_model->tnt($grade[$key])/($grade[$key])+0.2));
             $maxdg[$key] = min(intval($tmp), $grade[$key]);
             $r = $value - ($lv - 1) * $this->pet_model->tnt($tmp);
             //echo $r.'/';
         }
         //echo '<br>';
         foreach ($bpsql2min as $key => $value) {
             $tmp = $value / (($lv - 1) * 0.042 + 0.2);
             //$tmp = ( $value / ( ($lv-1) * $this->pet_model->tnt($grade[$key]) / ($grade[$key]) + 0.2 ) );
             $mindg[$key] = max(intval($tmp), $grade[$key] - 4);
             $r = $value - ($lv - 1) * $this->pet_model->tnt($tmp);
             //echo $tmp.'/';
         }
         //print_r($mindg);
         //print_r($maxdg);
         for ($xue = $mindg['xue']; $xue <= $maxdg['xue']; $xue++) {
             for ($gong = $mindg['gong']; $gong <= $maxdg['gong']; $gong++) {
                 for ($fang = $mindg['fang']; $fang <= $maxdg['fang']; $fang++) {
                     for ($min = $mindg['min']; $min <= $maxdg['min']; $min++) {
                         for ($mo = $mindg['mo']; $mo <= $maxdg['mo']; $mo++) {
                             $summinr = 0;
                             //每项bp扣除这个档次的bp的成长值和初始值的最大值剩下的总和的最小值,应该小于等于2+加点总和
                             $summaxr = 0;
                             $rg = array();
                             //随机档
                             foreach ($bpsql2min as $key => $value) {
                                 $rg[$key] = array();
                                 $rmin = $bpsql2min[$key] - ($lv - 1) * $this->pet_model->tnt(${$key}) - 0.2 * ${$key};
                                 $summinr += $rmin;
                                 $rmax = $bpsql2max[$key] - ($lv - 1) * $this->pet_model->tnt(${$key}) - 0.2 * ${$key};
                                 $summaxr += $rmax;
                                 //echo $rmin.'/'.$rmax.'<br>';
                                 for ($i = max(intval($rmin / 0.2) * 0.2, 0); $i <= min(intval($rmax / 0.2) * 0.2, 2); $i += 0.2) {
                                     $rg[$key][] = $i;
                                 }
                             }
                             if ($summinr <= 2 && $summaxr >= 2) {
                                 //print_r($rg);
                                 for ($i = 0; $i < count($rg['xue']); $i++) {
                                     for ($j = 0; $j < count($rg['gong']); $j++) {
                                         for ($k = 0; $k < count($rg['fang']); $k++) {
                                             for ($m = 0; $m < count($rg['min']); $m++) {
                                                 for ($n = 0; $n < count($rg['mo']); $n++) {
                                                     $sum = $rg['xue'][$i] + $rg['gong'][$j] + $rg['fang'][$k] + $rg['min'][$m] + $rg['mo'][$n];
                                                     if ($sum == 2) {
                                                         $rgrade = $rg['xue'][$i] * 5 . '' . $rg['gong'][$j] * 5 . '' . $rg['fang'][$k] * 5 . '' . $rg['min'][$m] * 5 . '' . $rg['mo'][$n] * 5;
                                                         $dgrade = -$xue + $grade['xue'] . '' . (-$gong + $grade['gong']) . '' . (-$fang + $grade['fang']) . '' . (-$min + $grade['min']) . '' . (-$mo + $grade['mo']);
                                                         $propGenRange = $this->pet_model->genPet($grade, $lv, $dgrade, $rgrade, implode(',', $addBP));
                                                         $inRange = $this->pet_model->checkPropInRange($prop, $propGenRange[1], $propGenRange[2]);
                                                         $pettemp = $propGenRange[0];
                                                         $propDist = $this->pet_model->getPropDist($this->pet_model->petToProp($pettemp), $prop);
                                                         //echo ($rg['xue'][$i]*5).'/'.($rg['gong'][$j]*5).'/'.($rg['fang'][$k]*5).'/'.($rg['min'][$m]*5).'/'.($rg['mo'][$n]*5).':::';
                                                         if ($inRange) {
                                                             echo $rgrade . '::' . $dgrade . '=' . $propDist . ' ' . sum(minus($this->pet_model->petToProp($pettemp), $prop)) . '<br>';
                                                         }
                                                         //echo ($xue-$grade['xue']).'/'. ($gong-$grade['gong']).'/'. ($fang-$grade['fang']).'/'. ($min-$grade['min']).'/'. ($mo-$grade['mo']).'/'.'<br>';
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         //die(0);
     }
     //end foreach pet
 }
Ejemplo n.º 7
0
			<input type="submit" />
		</form>
	</body>
</html>
<?php
include("./lib.php");
$operand1 = isset($_POST["operand1"]) ? $_POST["operand1"] : false;
$operand2 = isset($_POST["operand2"]) ? $_POST["operand2"] : false;
if (($operand1 == false) || ($operand2 == false)) {
	exit;
}
if (!(is_numeric($operand1) && is_numeric($operand2))) {
	die("No numeric");
}
$operator = isset($_POST["operator"]) ? $_POST["operator"] : false;
if ($operator == false) {
	exit;
}
$result = 0;
if ($operator == "plus") {
	$result = plus($operand1, $operand2);
} else if ($operator == "minus") {
	$result = minus($operand1, $operand2);
} else if ($operator == "multiple") {
	$result = multiple($operand1, $operand2);
} else {
	$result = divide($operand1, $operand2);
}
echo($operand1." ".$operator." ".$operand2." = ".$result);
?>