Ejemplo n.º 1
0
function generateSimulationArray($dimension, $startNrC, $startNrH, $startNrP)
{
    $_SESSION["dimension"] = $dimension;
    $simulationArray = array();
    $simulationday = generateDay0($startNrC, $startNrH, $startNrP);
    $simulationArray[] = $simulationday;
    do {
        $simulationeaten = eat($simulationday);
        $simulationloved = love($simulationeaten);
        $simulationfaught = fight($simulationloved);
        $simulationmoved = move($simulationfaught);
        $simulationspawned = spawnOnePlant($simulationmoved);
        $simulationday = $simulationspawned;
        $simulationArray[] = $simulationday;
    } while (count($simulationday) - count(array_keys($simulationday, null)) < $dimension ** 2);
    return $simulationArray;
}
 public function simulate()
 {
     $_SESSION["dimension"] = $_POST["dimension"];
     $_SESSION["startNrPlants"] = $_POST["startNrPlants"];
     $_SESSION["startNrCarnivores"] = $_POST["startNrCarnivore"];
     $_SESSION["startNrHerbivores"] = $_POST["startNrHerbivore"];
     if ($_SESSION["startNrPlants"] + $_SESSION["startNrCarnivores"] + $_SESSION["startNrHerbivores"] > $_SESSION["dimension"] ** 2) {
         header('location:index_tmp.php?toocrowded=true');
         exit(0);
     }
     $day = 0;
     do {
         for ($i = 0; $i < $_SESSION["dimension"] ** 2; $i++) {
             $_SESSION["action"][] = false;
         }
         if ($day == 0) {
             $simulation[$day] = generateDay0();
             $simMatrix[$day] = array_chunk($simulation[$day], $_SESSION["dimension"]);
             for ($i = 0; $i < $_SESSION["dimension"]; $i++) {
                 for ($j = 0; $j < $_SESSION["dimension"]; $j++) {
                     if ($simMatrix[$day][$i][$j]) {
                         $_SESSION["simData"][] = array('dimension' => $_SESSION["dimension"], 'day' => $day, 'posx' => $i, 'posy' => $j, 'type' => $simMatrix[$day][$i][$j]['type'], 'lifeforce' => $simMatrix[$day][$i][$j]['life']);
                     }
                 }
             }
         }
         $day++;
         $simulation[$day] = $simulation[$day - 1];
         $simulation[$day] = eat($simulation[$day]);
         $simulation[$day] = love($simulation[$day]);
         $simulation[$day] = fight($simulation[$day]);
         $simulation[$day] = move($simulation[$day]);
         $simulation[$day] = spawnOnePlant($simulation[$day]);
         $simMatrix[$day] = array_chunk($simulation[$day], $_SESSION["dimension"]);
         for ($i = 0; $i < $_SESSION["dimension"]; $i++) {
             for ($j = 0; $j < $_SESSION["dimension"]; $j++) {
                 if ($simMatrix[$day][$i][$j]) {
                     $_SESSION["simData"][] = array('dimension' => $_SESSION["dimension"], 'day' => $day, 'posx' => $i, 'posy' => $j, 'type' => $simMatrix[$day][$i][$j]['type'], 'lifeforce' => $simMatrix[$day][$i][$j]['life']);
                 }
             }
         }
     } while (count($simulation[$day]) - count(array_keys($simulation[$day], null)) < $_SESSION["dimension"] ** 2);
     return $simMatrix;
 }
Ejemplo n.º 3
0
     maps();
 } elseif ($do[0] == "maps2") {
     include 'towns.php';
     maps2($do[1]);
 } elseif ($do[0] == "maps3") {
     include 'towns.php';
     maps3($do[1]);
 } elseif ($do[0] == "gotown") {
     include 'towns.php';
     travelto($do[1]);
 } elseif ($do[0] == "move") {
     include 'explore.php';
     move();
 } elseif ($do[0] == "fight") {
     include 'fight.php';
     fight();
 } elseif ($do[0] == "victory") {
     include 'fight.php';
     victory();
 } elseif ($do[0] == "drop") {
     include 'fight.php';
     drop();
 } elseif ($do[0] == "dead") {
     include 'fight.php';
     dead();
 } elseif ($do[0] == "duelo") {
     include 'duelo.php';
     duelo();
 } elseif ($do[0] == "verify") {
     header("Location: users.php?do=verify");
     die;
Ejemplo n.º 4
0
$minCost = 10000;
$maxCost = 0;
foreach ($weaponList as $weapon) {
    foreach ($armorList as $armor) {
        $secondRingList = $ringList;
        foreach ($ringList as $key => $firstRing) {
            unset($secondRingList[$key]);
            if (!empty($secondRingList)) {
                foreach ($secondRingList as $secondRing) {
                    $cost = $weapon['cost'] + $armor['cost'] + $firstRing['cost'] + $secondRing['cost'];
                    if ($cost > $minCost && $cost < $maxCost) {
                        continue;
                    }
                    $currentPlayer = $player;
                    $currentPlayer['damage'] += $weapon['damage'] + $firstRing['damage'] + $secondRing['damage'];
                    $currentPlayer['armor'] += $armor['armor'] + $firstRing['armor'] + $secondRing['armor'];
                    $fightWinner = fight($currentPlayer, $boss);
                    if ($fightWinner === 'player') {
                        $minCost = min($minCost, $cost);
                    } else {
                        $maxCost = max($maxCost, $cost);
                    }
                }
            }
        }
    }
}
print 'Part1: ' . $minCost;
print PHP_EOL;
print 'Part2: ' . $maxCost;
print PHP_EOL;
    if ($day == 0) {
        $simulation[$day] = generateDay0();
        $simMatrix[$day] = array_chunk($simulation[$day], $_SESSION["dimension"]);
        for ($i = 0; $i < $_SESSION["dimension"]; $i++) {
            for ($j = 0; $j < $_SESSION["dimension"]; $j++) {
                if ($simMatrix[$day][$i][$j]) {
                    $_SESSION["simData"][] = array('dimension' => $_SESSION["dimension"], 'day' => $day, 'posx' => $i, 'posy' => $j, 'type' => $simMatrix[$day][$i][$j]['type'], 'lifeforce' => $simMatrix[$day][$i][$j]['life']);
                }
            }
        }
    }
    $day++;
    $simulation[$day] = $simulation[$day - 1];
    $simulation[$day] = eat($simulation[$day]);
    $simulation[$day] = love($simulation[$day]);
    $simulation[$day] = fight($simulation[$day]);
    $simulation[$day] = move($simulation[$day]);
    $simulation[$day] = spawnOnePlant($simulation[$day]);
    $simMatrix[$day] = array_chunk($simulation[$day], $_SESSION["dimension"]);
    for ($i = 0; $i < $_SESSION["dimension"]; $i++) {
        for ($j = 0; $j < $_SESSION["dimension"]; $j++) {
            if ($simMatrix[$day][$i][$j]) {
                $_SESSION["simData"][] = array('dimension' => $_SESSION["dimension"], 'day' => $day, 'posx' => $i, 'posy' => $j, 'type' => $simMatrix[$day][$i][$j]['type'], 'lifeforce' => $simMatrix[$day][$i][$j]['life']);
            }
        }
    }
} while (count($simulation[$day]) - count(array_keys($simulation[$day], null)) < $_SESSION["dimension"] ** 2);
include 'presentation_temp.php';
?>
<!--<!DOCTYPE html>
<html>
Ejemplo n.º 6
0
        $this->healingFactor = $h * rand(5, 10);
    }
    public function getHeal()
    {
        return $this->healingFactor;
    }
    public function enrage($target)
    {
        $this->dmg = $this->dmg * $this->rage;
    }
    public function heal($target)
    {
        $this->hp = $this->hp + $this->healingFactor;
    }
}
$wolverine = new mutant(100, 10);
$wolverine->setHeal(5);
$wolverine->setEnrage(3);
$wolverine->setCritChance(5);
$batman = new human(100, 10);
$batman->setUtilityDamage(1.2);
$batman->setCritChance(10);
$superman = new kryptonian(100, 10);
$superman->setHeatRay(18);
$superman->setCritChance(20);
fight($superman, $wolverine);
echo "<pre>";
print_r($batman);
print_r($superman);
print_r($wolverine);
exit;
Ejemplo n.º 7
0
}
const PLAYER = 'player';
const ENEMY = 'enemy';
$equipment = ['Weapons' => [['name' => 'Dagger', 'cost' => 8, 'damage' => 4, 'armor' => 0], ['name' => 'Shortsword', 'cost' => 10, 'damage' => 5, 'armor' => 0], ['name' => 'Warhammer', 'cost' => 25, 'damage' => 6, 'armor' => 0], ['name' => 'Longsword', 'cost' => 40, 'damage' => 7, 'armor' => 0], ['name' => 'Greataxe', 'cost' => 74, 'damage' => 8, 'armor' => 0]], 'Armor' => [['name' => 'None', 'cost' => 0, 'damage' => 0, 'armor' => 0], ['name' => 'Leather', 'cost' => 13, 'damage' => 0, 'armor' => 1], ['name' => 'Chainmail', 'cost' => 31, 'damage' => 0, 'armor' => 2], ['name' => 'Splintmail', 'cost' => 53, 'damage' => 0, 'armor' => 3], ['name' => 'Bandedmail', 'cost' => 75, 'damage' => 0, 'armor' => 4], ['name' => 'Platemail', 'cost' => 102, 'damage' => 0, 'armor' => 5]], 'Rings' => [['name' => 'None1', 'cost' => 0, 'damage' => 0, 'armor' => 0], ['name' => 'None2', 'cost' => 0, 'damage' => 0, 'armor' => 0], ['name' => 'Damage +1', 'cost' => 25, 'damage' => 1, 'armor' => 0], ['name' => 'Damage +2', 'cost' => 50, 'damage' => 2, 'armor' => 0], ['name' => 'Damage +3', 'cost' => 100, 'damage' => 3, 'armor' => 0], ['name' => 'Defense +1', 'cost' => 20, 'damage' => 0, 'armor' => 1], ['name' => 'Defense +2', 'cost' => 40, 'damage' => 0, 'armor' => 2], ['name' => 'Defense +3', 'cost' => 80, 'damage' => 0, 'armor' => 3]]];
$ringCount = count($equipment['Rings']);
$minCost = 99999;
$maxCost = 0;
foreach ($equipment['Weapons'] as $weapon) {
    foreach ($equipment['Armor'] as $armor) {
        for ($i = 0; $i < $ringCount - 1; $i++) {
            $ring1 = $equipment['Rings'][$i];
            for ($j = $i + 1; $j < $ringCount; $j++) {
                $ring2 = $equipment['Rings'][$j];
                $items = [$weapon, $armor, $ring1, $ring2];
                $fighter = equip($player, $items);
                $result = fight($fighter, $enemy);
                if ($result == PLAYER) {
                    if ($fighter['cost'] < $minCost) {
                        $minCost = $fighter['cost'];
                    }
                } elseif ($result == ENEMY) {
                    if ($fighter['cost'] > $maxCost) {
                        $maxCost = $fighter['cost'];
                    }
                }
            }
        }
    }
}
print "MinCost to win: {$minCost} \n";
print "MaxCost to lose: {$maxCost} \n";
Ejemplo n.º 8
0
function verificaEnconterPlayer(&$enemys, &$player)
{
    if ($_SESSION['totalEnemy'] > 0) {
        list($y, $posX) = each($player);
        list($x) = each($posX);
        // se tem enemy sobre
        if (isset($enemys[$y - 1][$x])) {
            return fight();
        } elseif (isset($enemys[$y + 1][$x])) {
            return fight();
        } elseif (isset($enemys[$y][$x - 1])) {
            return fight();
        } elseif (isset($enemys[$y][$x + 1])) {
            return fight();
        }
    }
    return false;
}
Ejemplo n.º 9
0
/**
 * 1 Magic Missile costs 53 mana. It instantly does 4 damage.
 * 2 Drain costs 73 mana. It instantly does 2 damage and heals you for 2 hit points.
 * 3 Shield costs 113 mana. It starts an effect that lasts for 6 turns. While it is active, your armor is increased by 7.
 * 4 Poison costs 173 mana. It starts an effect that lasts for 6 turns. At the start of each turn while it is active, it deals the boss 3 damage.
 * 5 Recharge costs 229 mana. It starts an effect that lasts for 5 turns. At the start of each turn while it is active, it gives you 101 new mana.
 */
function fight($mageHp, $bossHp, $mana, $tickShield, $tickPoison, $tickRestore, $nextSpell, $cost)
{
    global $bossDamage, $best;
    if (\min($best, $cost) != $cost) {
        return;
    }
    // START TASK 2
    $mageHp--;
    if ($mageHp <= 0) {
        return;
    }
    // END TASK 2
    // Check current spell and apply it
    if ($nextSpell == 1) {
        if ($mana < 53) {
            return;
        } else {
            $mana -= 53;
            $cost += 53;
            $bossHp -= 4;
            if ($bossHp <= 0) {
                $best = \min($best, $cost);
                return;
            }
        }
    }
    if ($nextSpell == 2) {
        if ($mana < 73) {
            return;
        } else {
            $mana -= 73;
            $cost += 73;
            $bossHp -= 2;
            $mageHp += 2;
            if ($bossHp <= 0) {
                $best = \min($best, $cost);
                return;
            }
        }
    }
    if ($nextSpell == 3) {
        if ($mana < 113 || $tickShield) {
            return;
        } else {
            $mana -= 113;
            $cost += 113;
            $tickShield = 6;
        }
    }
    if ($nextSpell == 4) {
        if ($mana < 173 || $tickPoison) {
            return;
        } else {
            $mana -= 173;
            $cost += 173;
            $tickPoison = 6;
        }
    }
    if ($nextSpell == 5) {
        if ($mana < 229 || $tickRestore) {
            return;
        } else {
            $mana -= 229;
            $cost += 229;
            $tickRestore = 5;
        }
    }
    // Check ticks and do boss dmg
    if ($tickPoison) {
        $bossHp -= 3;
        $tickPoison--;
        if ($bossHp <= 0) {
            $best = \min($best, $cost);
            return;
        }
    }
    if ($tickRestore) {
        $mana += 101;
        $tickRestore--;
    }
    if ($tickShield) {
        $tickShield--;
        $mageHp -= \max(1, $bossDamage - 7);
    } else {
        $mageHp -= $bossDamage;
    }
    if ($mageHp <= 0) {
        return;
    }
    // Check ticks and choose next spell
    if ($tickPoison) {
        $bossHp -= 3;
        $tickPoison--;
        if ($bossHp <= 0) {
            $best = \min($best, $cost);
            return;
        }
    }
    if ($tickRestore) {
        $mana += 101;
        $tickRestore--;
    }
    if ($tickShield) {
        $tickShield--;
    }
    for ($i = 1; $i <= 5; $i++) {
        \fight($mageHp, $bossHp, $mana, $tickShield, $tickPoison, $tickRestore, $i, $cost);
    }
}