<?php
header("Content-Type: text/plain; charset=utf-8"); class Hero
{
public $health;
public $armorLow;
public $armorHigh;
public $block;
public $dodgeCrit;
public $crit;
public $attackLow;
public $attackHigh;
public $charisma;
public $agility;
public $skill;
public function __construct($attackLow, $attackHigh, $health, $armorLow, $armorHigh, $block, $dodgeCrit, $crit, $charisma, $agility, $skill)
{
$this->attackLow = $attackLow;
$this->attackHigh = $attackHigh;
$this->health = $health;
$this->armorLow = $armorLow;
$this->armorHigh = $armorHigh;
$this->block = $block;
$this->dodgeCrit = $dodgeCrit;
$this->crit = $crit;
$this->charisma = $charisma;
$this->agility = $agility;
$this->skill = $skill;
}
public function isChance($attribute) //общая функция для крита и блока
{
if ((mt_rand(1, 100)) < $attribute) { return 1;
}
return 0;
}
public function getDmg()
{
return mt_rand($this->attackLow, $this->attackHigh); }
public function getDef()
{
return mt_rand($this->armorLow, $this->armorHigh); }
}
class Game
{
public $heroes = array(); public $cloned = array(); public function __construct($hero1, $hero2)
{
$this->heroes[] = $hero1;
$this->heroes[] = $hero2;
$hero12 = clone $hero1;
$hero22 = clone $hero2;
$this->cloned[] = $hero12;
$this->cloned[] = $hero22;
}
public function getHit($k) // $k = 0 либо 1 (номер игрока который наносит урон)
{
foreach ($this->heroes as $number => $hero) {
if ($number == $k) {
$skill = $hero->skill;
$dmg = $hero->getDmg();
$crit = 1; // коефициент крита умножаемый на основной урон в случае отстутвия крита
if ($hero->isChance($hero->crit)) {
$crit = 2; // -||- в случае крита
}
} else {
$def = $hero->getDef();
$block = 1; // коефициент блока умножаемый на основной урон (в случае отсутствие блока)
$avoidAttackStat = $hero->skill + $hero->agility;
$avoidCrit = $hero->dodgeCrit;
if ($hero->isChance($hero->block)) {
$block = 0; // -||- в случае успешного блока
}
}
}
$hitChance = round($skill * 100 / $avoidAttackStat); $dodge = 0;
if ((mt_rand(1, 100)) < $hitChance) { $dodge = 1; // коефициент промаха (уменние / (умение и ловкость врага)) умножается на основной урон
}
if ($crit == 2 && (mt_rand(1, 100)) < $avoidCrit) // проверка на избежание крита {
$crit = 1;
}
$dmg = ($dmg - $def) * $crit * $block * $dodge;
return $dmg;
}
public function isDoubleHit($k) // $k - номер героя (0 либо 1)
{
foreach ($this->heroes as $number => $hero) {
if ($number == $k) {
$charMain = $hero->charisma;
} else {
$charEnemy = $hero->charisma;
}
}
if ($charMain < $charEnemy || $charMain == $charEnemy) {
return 0; // вернет 0 в случае если у нашего героя меньше либо столько же харизмы как у врага
}
$coef = $charMain - $charEnemy;
return 1; // двойная атака
} else {
return 0;
}
}
public function isAlive($k, $dmg) //номер героя (0,1)
{
foreach ($this->heroes as $number => $hero) {
if ($number != $k) {
if ($hero->health <= $dmg) {
$hero->health = 1;
return;
}
$hero->health -= $dmg;
}
}
}
public function getRound()
{
for ($i = 0; $i <= 1; $i++) {
if ($this->isDoubleHit($i)) {
$dmg = $this->getHit($i) + $this->getHit($i);
} else {
$dmg = $this->getHit($i);
}
$this->isAlive($i, $dmg);
}
}
public function getGame()
{
for ($i = 1; $i <= 20; $i++) {
$this->getRound();
}
foreach ($this->heroes as $number => $hero) {
$health[$number] = $this->cloned[$number]->health - $hero->health;
}
list($healthOne, $healthTwo) = $health; $this->heroes = $this->cloned;
if ($healthOne < $healthTwo) {
return 0; //победа первого
} elseif ($healthOne > $healthTwo) {
return 1; //победа второго
} elseif ($healthOne == $healthTwo) {
return 2; //ничья
}
}
}
$hero1 = new Hero(504, 563, 19520, 225, 276, 39, 25, 51, 1276, 890, 1182);
$hero2 = new Hero(350, 397, 14275, 25, 27, 50, 25, 41, 775, 774, 928);
$game = new Game($hero1, $hero2);
$k = 1000;
$first = 0;
$second = 0;
$draw = 0;
for ($i = 1; $i <= $k; $i++) {
$win = $game->getGame();
if ($win == 0) {
$first++;
} elseif ($win == 1) {
$second++;
} elseif ($win == 2) {
$draw++;
}
}
echo $first;
echo "\n";
echo $second;
echo "\n";
echo $draw;
echo "\n";
$first = round((($first * 100) / $k), 2); $second = round((($second * 100) / $k), 2); $draw = round((($draw * 100) / $k), 2); echo $first;
echo "\n";
echo $second;
echo "\n";
echo $draw;
echo "\n";
PD9waHAKaGVhZGVyKCJDb250ZW50LVR5cGU6IHRleHQvcGxhaW47IGNoYXJzZXQ9dXRmLTgiKTsKbWJfaW50ZXJuYWxfZW5jb2RpbmcoIlVURi04Iik7CmNsYXNzIEhlcm8KewogICAgcHVibGljICRoZWFsdGg7CiAgICBwdWJsaWMgJGFybW9yTG93OwogICAgcHVibGljICRhcm1vckhpZ2g7CiAgICBwdWJsaWMgJGJsb2NrOwogICAgcHVibGljICRkb2RnZUNyaXQ7CiAgICBwdWJsaWMgJGNyaXQ7CiAgICBwdWJsaWMgJGF0dGFja0xvdzsKICAgIHB1YmxpYyAkYXR0YWNrSGlnaDsKICAgIHB1YmxpYyAkY2hhcmlzbWE7CiAgICBwdWJsaWMgJGFnaWxpdHk7CiAgICBwdWJsaWMgJHNraWxsOwogICAgcHVibGljIGZ1bmN0aW9uIF9fY29uc3RydWN0KCRhdHRhY2tMb3csICRhdHRhY2tIaWdoLCAkaGVhbHRoLCAkYXJtb3JMb3csICRhcm1vckhpZ2gsICRibG9jaywgJGRvZGdlQ3JpdCwgJGNyaXQsICRjaGFyaXNtYSwgJGFnaWxpdHksICRza2lsbCkKICAgIHsKICAgICAgICAkdGhpcy0+YXR0YWNrTG93ICA9ICRhdHRhY2tMb3c7CiAgICAgICAgJHRoaXMtPmF0dGFja0hpZ2ggPSAkYXR0YWNrSGlnaDsKICAgICAgICAkdGhpcy0+aGVhbHRoICAgICA9ICRoZWFsdGg7CiAgICAgICAgJHRoaXMtPmFybW9yTG93ICAgPSAkYXJtb3JMb3c7CiAgICAgICAgJHRoaXMtPmFybW9ySGlnaCAgPSAkYXJtb3JIaWdoOwogICAgICAgICR0aGlzLT5ibG9jayAgICAgID0gJGJsb2NrOwogICAgICAgICR0aGlzLT5kb2RnZUNyaXQgID0gJGRvZGdlQ3JpdDsKICAgICAgICAkdGhpcy0+Y3JpdCAgICAgICA9ICRjcml0OwogICAgICAgICR0aGlzLT5jaGFyaXNtYSAgID0gJGNoYXJpc21hOwogICAgICAgICR0aGlzLT5hZ2lsaXR5ICAgID0gJGFnaWxpdHk7CiAgICAgICAgJHRoaXMtPnNraWxsICAgICAgPSAkc2tpbGw7CiAgICB9CiAgICBwdWJsaWMgZnVuY3Rpb24gaXNDaGFuY2UoJGF0dHJpYnV0ZSkgLy/QvtCx0YnQsNGPINGE0YPQvdC60YbQuNGPINC00LvRjyDQutGA0LjRgtCwINC4INCx0LvQvtC60LAKICAgIHsKICAgICAgICBpZiAoKG10X3JhbmQoMSwgMTAwKSkgPCAkYXR0cmlidXRlKSB7CiAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgIH0KICAgICAgICByZXR1cm4gMDsKICAgIH0KICAgIHB1YmxpYyBmdW5jdGlvbiBnZXREbWcoKQogICAgewogICAgICAgIHJldHVybiBtdF9yYW5kKCR0aGlzLT5hdHRhY2tMb3csICR0aGlzLT5hdHRhY2tIaWdoKTsKICAgIH0KICAgIHB1YmxpYyBmdW5jdGlvbiBnZXREZWYoKQogICAgewogICAgICAgIHJldHVybiBtdF9yYW5kKCR0aGlzLT5hcm1vckxvdywgJHRoaXMtPmFybW9ySGlnaCk7CiAgICB9CiAgICAKfQpjbGFzcyBHYW1lCnsKICAgIHB1YmxpYyAkaGVyb2VzID0gYXJyYXkoKTsKICAgIHB1YmxpYyAkY2xvbmVkID0gYXJyYXkoKTsKICAgIHB1YmxpYyBmdW5jdGlvbiBfX2NvbnN0cnVjdCgkaGVybzEsICRoZXJvMikKICAgIHsKICAgICAgICAkdGhpcy0+aGVyb2VzW10gPSAkaGVybzE7CiAgICAgICAgJHRoaXMtPmhlcm9lc1tdID0gJGhlcm8yOwogICAgICAgICRoZXJvMTIgICAgICAgICA9IGNsb25lICRoZXJvMTsKICAgICAgICAkaGVybzIyICAgICAgICAgPSBjbG9uZSAkaGVybzI7CiAgICAgICAgJHRoaXMtPmNsb25lZFtdID0gJGhlcm8xMjsKICAgICAgICAkdGhpcy0+Y2xvbmVkW10gPSAkaGVybzIyOwogICAgfQogICAgcHVibGljIGZ1bmN0aW9uIGdldEhpdCgkaykgLy8gJGsgPSAwINC70LjQsdC+IDEgKNC90L7QvNC10YAg0LjQs9GA0L7QutCwINC60L7RgtC+0YDRi9C5INC90LDQvdC+0YHQuNGCINGD0YDQvtC9KQogICAgewogICAgICAgIGZvcmVhY2ggKCR0aGlzLT5oZXJvZXMgYXMgJG51bWJlciA9PiAkaGVybykgewogICAgICAgICAgICBpZiAoJG51bWJlciA9PSAkaykgewogICAgICAgICAgICAgICAgJHNraWxsID0gJGhlcm8tPnNraWxsOwogICAgICAgICAgICAgICAgJGRtZyAgID0gJGhlcm8tPmdldERtZygpOwogICAgICAgICAgICAgICAgJGNyaXQgID0gMTsgLy8g0LrQvtC10YTQuNGG0LjQtdC90YIg0LrRgNC40YLQsCDRg9C80L3QvtC20LDQtdC80YvQuSDQvdCwINC+0YHQvdC+0LLQvdC+0Lkg0YPRgNC+0L0g0LIg0YHQu9GD0YfQsNC1INC+0YLRgdGC0YPRgtCy0LjRjyDQutGA0LjRgtCwCiAgICAgICAgICAgICAgICBpZiAoJGhlcm8tPmlzQ2hhbmNlKCRoZXJvLT5jcml0KSkgewogICAgICAgICAgICAgICAgICAgICRjcml0ID0gMjsgLy8gLXx8LSDQsiDRgdC70YPRh9Cw0LUg0LrRgNC40YLQsAogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgJGRlZiAgICAgICAgICAgICA9ICRoZXJvLT5nZXREZWYoKTsKICAgICAgICAgICAgICAgICRibG9jayAgICAgICAgICAgPSAxOyAvLyDQutC+0LXRhNC40YbQuNC10L3RgiDQsdC70L7QutCwINGD0LzQvdC+0LbQsNC10LzRi9C5INC90LAg0L7RgdC90L7QstC90L7QuSDRg9GA0L7QvSAo0LIg0YHQu9GD0YfQsNC1INC+0YLRgdGD0YLRgdGC0LLQuNC1INCx0LvQvtC60LApCQkJCQogICAgICAgICAgICAgICAgJGF2b2lkQXR0YWNrU3RhdCA9ICRoZXJvLT5za2lsbCArICRoZXJvLT5hZ2lsaXR5OwogICAgICAgICAgICAgICAgJGF2b2lkQ3JpdCAgICAgICA9ICRoZXJvLT5kb2RnZUNyaXQ7CiAgICAgICAgICAgICAgICBpZiAoJGhlcm8tPmlzQ2hhbmNlKCRoZXJvLT5ibG9jaykpIHsKICAgICAgICAgICAgICAgICAgICAkYmxvY2sgPSAwOyAvLyAtfHwtINCyINGB0LvRg9GH0LDQtSDRg9GB0L/QtdGI0L3QvtCz0L4g0LHQu9C+0LrQsAogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgICRoaXRDaGFuY2UgPSByb3VuZCgkc2tpbGwgKiAxMDAgLyAkYXZvaWRBdHRhY2tTdGF0KTsKICAgICAgICAkZG9kZ2UgICAgID0gMDsKICAgICAgICBpZiAoKG10X3JhbmQoMSwgMTAwKSkgPCAkaGl0Q2hhbmNlKSB7CiAgICAgICAgICAgICRkb2RnZSA9IDE7IC8vINC60L7QtdGE0LjRhtC40LXQvdGCINC/0YDQvtC80LDRhdCwICjRg9C80LXQvdC90LjQtSAvICjRg9C80LXQvdC40LUg0Lgg0LvQvtCy0LrQvtGB0YLRjCDQstGA0LDQs9CwKSkg0YPQvNC90L7QttCw0LXRgtGB0Y8g0L3QsCDQvtGB0L3QvtCy0L3QvtC5INGD0YDQvtC9CiAgICAgICAgfQogICAgICAgIGlmICgkY3JpdCA9PSAyICYmIChtdF9yYW5kKDEsIDEwMCkpIDwgJGF2b2lkQ3JpdCkgLy8g0L/RgNC+0LLQtdGA0LrQsCDQvdCwINC40LfQsdC10LbQsNC90LjQtSDQutGA0LjRgtCwCiAgICAgICAgICAgIHsKICAgICAgICAgICAgJGNyaXQgPSAxOwogICAgICAgICAgICAKICAgICAgICB9CiAgICAgICAgJGRtZyA9ICgkZG1nIC0gJGRlZikgKiAkY3JpdCAqICRibG9jayAqICRkb2RnZTsKICAgICAgICByZXR1cm4gJGRtZzsKICAgIH0KICAgIHB1YmxpYyBmdW5jdGlvbiBpc0RvdWJsZUhpdCgkaykgLy8gJGsgLSDQvdC+0LzQtdGAINCz0LXRgNC+0Y8gKDAg0LvQuNCx0L4gMSkKICAgIHsKICAgICAgICBmb3JlYWNoICgkdGhpcy0+aGVyb2VzIGFzICRudW1iZXIgPT4gJGhlcm8pIHsKICAgICAgICAgICAgaWYgKCRudW1iZXIgPT0gJGspIHsKICAgICAgICAgICAgICAgICRjaGFyTWFpbiA9ICRoZXJvLT5jaGFyaXNtYTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICRjaGFyRW5lbXkgPSAkaGVyby0+Y2hhcmlzbWE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgCiAgICAgICAgfQogICAgICAgIGlmICgkY2hhck1haW4gPCAkY2hhckVuZW15IHx8ICRjaGFyTWFpbiA9PSAkY2hhckVuZW15KSB7CiAgICAgICAgICAgIHJldHVybiAwOyAvLyDQstC10YDQvdC10YIgMCDQsiDRgdC70YPRh9Cw0LUg0LXRgdC70Lgg0YMg0L3QsNGI0LXQs9C+INCz0LXRgNC+0Y8g0LzQtdC90YzRiNC1INC70LjQsdC+INGB0YLQvtC70YzQutC+INC20LUg0YXQsNGA0LjQt9C80Ysg0LrQsNC6INGDINCy0YDQsNCz0LAKICAgICAgICB9CiAgICAgICAgJGNvZWYgPSAkY2hhck1haW4gLSAkY2hhckVuZW15OwogICAgICAgIGlmICgobXRfcmFuZCgxLCAxMDApKSA8ICRjb2VmKSB7CiAgICAgICAgICAgIHJldHVybiAxOyAvLyDQtNCy0L7QudC90LDRjyDQsNGC0LDQutCwCiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQogICAgICAgIAogICAgfQogICAgcHVibGljIGZ1bmN0aW9uIGlzQWxpdmUoJGssICRkbWcpIC8v0L3QvtC80LXRgCDQs9C10YDQvtGPICgwLDEpCiAgICB7CiAgICAgICAgZm9yZWFjaCAoJHRoaXMtPmhlcm9lcyBhcyAkbnVtYmVyID0+ICRoZXJvKSB7CiAgICAgICAgICAgIGlmICgkbnVtYmVyICE9ICRrKSB7CiAgICAgICAgICAgICAgICBpZiAoJGhlcm8tPmhlYWx0aCA8PSAkZG1nKSB7CiAgICAgICAgICAgICAgICAgICAgJGhlcm8tPmhlYWx0aCA9IDE7CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgJGhlcm8tPmhlYWx0aCAtPSAkZG1nOwogICAgICAgICAgICB9CiAgICAgICAgICAgIAogICAgICAgIH0KICAgICAgICAKICAgIH0KICAgIHB1YmxpYyBmdW5jdGlvbiBnZXRSb3VuZCgpCiAgICB7CiAgICAgICAgZm9yICgkaSA9IDA7ICRpIDw9IDE7ICRpKyspIHsKICAgICAgICAgICAgaWYgKCR0aGlzLT5pc0RvdWJsZUhpdCgkaSkpIHsKICAgICAgICAgICAgICAgICRkbWcgPSAkdGhpcy0+Z2V0SGl0KCRpKSArICR0aGlzLT5nZXRIaXQoJGkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgJGRtZyA9ICR0aGlzLT5nZXRIaXQoJGkpOwogICAgICAgICAgICB9CiAgICAgICAgICAgICR0aGlzLT5pc0FsaXZlKCRpLCAkZG1nKTsKICAgICAgICB9CiAgICB9CiAgICBwdWJsaWMgZnVuY3Rpb24gZ2V0R2FtZSgpCiAgICB7CiAgICAgICAgZm9yICgkaSA9IDE7ICRpIDw9IDIwOyAkaSsrKSB7CiAgICAgICAgICAgICR0aGlzLT5nZXRSb3VuZCgpOwogICAgICAgIH0KICAgICAgICAkaGVhbHRoID0gYXJyYXkoKTsKICAgICAgICBmb3JlYWNoICgkdGhpcy0+aGVyb2VzIGFzICRudW1iZXIgPT4gJGhlcm8pIHsKICAgICAgICAgICAgJGhlYWx0aFskbnVt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