Добавил собственно симуляцию игрового процесса

This commit is contained in:
ftc
2025-09-25 23:56:59 +03:00
parent 2a54332e4b
commit 3abfdcd82a
+111
View File
@@ -128,6 +128,40 @@ class DeckForm extends Model
return false; 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() private function generateTry()
{ {
$this->fillDeck(); $this->fillDeck();
@@ -144,6 +178,7 @@ class DeckForm extends Model
while (count($this->hand) < 5) $this->hand[] = array_pop($this->deck); while (count($this->hand) < 5) $this->hand[] = array_pop($this->deck);
foreach ($replace as $r) $this->deck[] = $r; foreach ($replace as $r) $this->deck[] = $r;
$this->shuffleDeck(); $this->shuffleDeck();
$initiate_played = false;
for ($round = 0; $round < self::COMPUTE_ROUNDS; $round++) for ($round = 0; $round < self::COMPUTE_ROUNDS; $round++)
{ {
if ($this->haveWeapon()) if ($this->haveWeapon())
@@ -151,6 +186,82 @@ class DeckForm extends Model
$this->addProb($round); $this->addProb($round);
return; 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;
}
} }
} }
} }