From 3abfdcd82aeb4d3c3867558746349d631a0e32c0 Mon Sep 17 00:00:00 2001 From: Denis Denisov Date: Thu, 25 Sep 2025 23:56:59 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B1=D1=81=D1=82=D0=B2=D0=B5=D0=BD=D0=BD=D0=BE=20?= =?UTF-8?q?=D1=81=D0=B8=D0=BC=D1=83=D0=BB=D1=8F=D1=86=D0=B8=D1=8E=20=D0=B8?= =?UTF-8?q?=D0=B3=D1=80=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D1=86=D0=B5=D1=81=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/DeckForm.php | 111 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/models/DeckForm.php b/models/DeckForm.php index df85955..786f998 100644 --- a/models/DeckForm.php +++ b/models/DeckForm.php @@ -128,6 +128,40 @@ class DeckForm extends Model return false; } + private function tryPlay($card) + { + for ($i = 0; $i < count($this->hand); $i++) + { + if ($this->hand[$i] == $card) + { + $this->hand[$i] = $this->hand[count($this->hand) - 1]; + array_pop($this->hand); + return true; + } + } + return false; + } + + private function removeFromDeck($i) + { + $this->deck[$i] = $this->deck[count($this->deck) - 1]; + array_pop($this->deck); + } + + private function useInitiate() + { + for ($i = count($this->deck) - 1; $i >= 0 && $i > count($this->deck) - 4; $i--) + { + if ($this->deck[$i] == self::CARD_WEAPON_SPELL) + { + $this->removeFromDeck($i); + $this->hand[] = self::CARD_WEAPON_SPELL; + break; + } + } + $this->shuffleDeck(); + } + private function generateTry() { $this->fillDeck(); @@ -144,6 +178,7 @@ class DeckForm extends Model while (count($this->hand) < 5) $this->hand[] = array_pop($this->deck); foreach ($replace as $r) $this->deck[] = $r; $this->shuffleDeck(); + $initiate_played = false; for ($round = 0; $round < self::COMPUTE_ROUNDS; $round++) { if ($this->haveWeapon()) @@ -151,6 +186,82 @@ class DeckForm extends Model $this->addProb($round); return; } + $initiate_used = false; + for ($action = 0; $action < 3; $action++) + { + if (!$initiate_used) + { + $this->useInitiate(); + $initiate_used = true; + } + if ($this->tryPlay(self::CARD_WEAPON_ITEM)) + { + $this->addProb($round); + return; + } + if ($this->tryPlay(self::CARD_WEAPON_SPELL)) + { + $this->addProb($round); + return; + } + // try do best action + if ($this->tryPlay(self::CARD_PREPARED)) + { + for ($i = count($this->deck) - 1; $i >= 0 && $i > count($this->deck) - 10; $i--) + { + if ($this->deck[$i] == self::CARD_WEAPON_ITEM || + $this->deck[$i] == self::CARD_WEAPON_SPELL) + { + $this->hand[] = $this->deck[$i]; + $this->removeFromDeck($i); + break; + } + } + $this->shuffleDeck(); + continue; + } + if ($this->tryPlay(self::CARD_BACKPACK_2)) + { + for ($i = count($this->deck) - 1; $i >= 0 && $i > count($this->deck) - 13; $i--) + { + if ($this->deck[$i] == self::CARD_WEAPON_ITEM) + { + $this->removeFromDeck($i); + $this->hand[] = self::CARD_WEAPON_ITEM; + break; + } + } + $this->shuffleDeck(); + continue; + } + if ($this->tryPlay(self::CARD_BACKPACK_0)) + { + for ($i = count($this->deck) - 1; $i >= 0 && $i > count($this->deck) - 7; $i--) + { + if ($this->deck[$i] == self::CARD_WEAPON_ITEM) + { + $this->removeFromDeck($i); + $this->hand[] = self::CARD_WEAPON_ITEM; + break; + } + } + $this->shuffleDeck(); + continue; + } + if ($this->weapons_spells > 0 && !$initiate_played) + { + if ($this->tryPlay(self::CARD_INITIATE)) + { + $initiate_played = true; + } + } + $this->hand[] = array_pop($this->deck); + } + if (!$initiate_used) + { + $this->useInitiate(); + $initiate_used = true; + } } } }