Classe : Schwan\MTG\Controller\Math02

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
Math02 extends Math
{
/**
* @args void
* @return bool
*/
function populate()
{
if(empty(
$_REQUEST['turn_size']))
{
$_REQUEST['turn_size'] = 5;
}

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

if(empty(
$_REQUEST['deck_size']))
{
$_REQUEST['deck_size'] = 60;

#
return parent::populate();
}

#
$_REQUEST['deck_size'] = min(99, $_REQUEST['deck_size']);
$_REQUEST['land_size'] = min($_REQUEST['land_size'], $_REQUEST['deck_size']);
$_REQUEST['turn_size'] = min($_REQUEST['turn_size'], $_REQUEST['land_size']);

$deck = array_fill(0, $_REQUEST['deck_size'], 0);

for(
$id = 0; $id < $_REQUEST['land_size']; $id++)
{
$deck[$id] = 1;
}

$this->deck = $deck;

return
parent::populate();
}

/**
* @args void
* @return bool
*/
function calculate()
{
$deck = $this->deck;
$k_max = $_REQUEST['turn_size'] + ($_REQUEST['game_start_status'] ? 8 : 7);

shuffle($deck);
$s = 0;

for(
$k = 0; $k < $k_max; $k++)
{
$s += $deck[$k];
}

return !(
$s < $_REQUEST['turn_size']);
}
}
}