Classe : Schwan\MTG\Controller\Math03

Fichier PHP
| Mardi 12 Mars 2024, 18:17:52

<?php
/**
* MTG Schwan
*
* GNU General Public License
*
* Copyright © 2020 - 2022, Yohann Schwan. All rights reserved.
*/
namespace Schwan\MTG\Controller {

class
Math03 extends Math
{
/**
* @args void
* @return bool
*/
function populate()
{

if(empty(
$_REQUEST['land_size']))
{
$_REQUEST['land_size'] = 40;
}

if(empty(
$_REQUEST['mana_rock_size']))
{
$_REQUEST['mana_rock_size'] = 10;
}

if(empty(
$_REQUEST['deck_size']))
{
$_REQUEST['deck_size'] = 99;
return
parent::populate();
}

$_REQUEST['deck_size'] = max($_REQUEST['deck_size'], $_REQUEST['land_size'] + $_REQUEST['mana_rock_size']);

#
# Deck Building
#
$this->deck = array_fill(0, $_REQUEST['deck_size'], 0);

for(
$id_1 = 0; $id_1 < $_REQUEST['land_size']; $id_1++)
{
$this->deck[$id_1] = 1;
}

for(
$id_2 = 0; $id_2 < $_REQUEST['mana_rock_size']; $id_2++)
{
$this->deck[$id_1 + $id_2] = 2;
}

return
parent::populate();
}

/**
* @args void
* @return bool
*/
function calculate()
{
$deck = $this->deck;

# Etape 0
shuffle($deck);

# Etape 1 : piocher la main de départ, puis les cartes des T1, T2 et T3.
$max = $_REQUEST['game_start_status'] ? 7 : 6;

$hand = array_slice($deck, 0, $max);
$c1 = $deck[$max];
$c2 = $deck[$max + 1];
$c3 = $deck[$max + 2];

# Etape 2 : analyse tour par tour.
$deck[] = $c1;

if(
is_int($k = array_search(1, $hand)))
{
unset(
$deck[$k]);
}
else {

return
false;
}

$deck[] = $c2;

if(
is_int($k = array_search(1, $hand)))
{
unset(
$deck[$k]);
}
else {

return
false;
}

if(
is_int($k = array_search(2, $hand)))
{
unset(
$deck[$k]);
}
else {

return
false;
}

$deck[] = $c3;

if(
is_int($k = array_search(1, $hand)))
{
unset(
$deck[$k]);
}
else {

return
false;
}

return
true;
}
}
}