Implemented setting board if not set yet

This commit is contained in:
Jeroen De Meerleer 2019-09-28 20:54:59 +02:00
parent 1708a54d0a
commit 2eb570ce7c
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6

View File

@ -226,6 +226,10 @@ class Tournament
/** @var Pairing[] */ /** @var Pairing[] */
$cache = array(); $cache = array();
/** @var int[] */
$lastboards;
/** @var Pairing $pairing */
foreach ($pairings as $pairing) { foreach ($pairings as $pairing) {
// Add pairing to player // Add pairing to player
$pairing->getPlayer()->addPairing($pairing); $pairing->getPlayer()->addPairing($pairing);
@ -234,6 +238,11 @@ class Tournament
$this->getRoundByNo($round)->addPairing($pairing); $this->getRoundByNo($round)->addPairing($pairing);
$opponent = null; $opponent = null;
/**
* @var int $key
* @var Pairing $cached
*/
foreach ($cache as $key=>$cached) { foreach ($cache as $key=>$cached) {
if (!is_null($cached)) { if (!is_null($cached)) {
if (($cached->getOpponent() == $pairing->getPlayer()) && ($cached->getRound() == $pairing->getRound())) { if (($cached->getOpponent() == $pairing->getPlayer()) && ($cached->getRound() == $pairing->getRound())) {
@ -257,6 +266,18 @@ class Tournament
} else { } else {
// Check if game already exists // Check if game already exists
if (!$this->gameExists($game, $round)) { if (!$this->gameExists($game, $round)) {
$game->setBoard($game->getWhite()->getBoard());
// Add board if inexistent
if($game->getBoard() == -1) {
if (isset($lastboards[$round])) {
$lastboards[$round] += 1;
} else {
$lastboards[$round] = 0;
}
$game->setBoard($lastboards[$round]);
$game->getWhite()->setBoard($lastboards[$round]);
$game->getBlack()->setBoard($lastboards[$round]);
}
$this->AddGame($game, $round); $this->AddGame($game, $round);
} }
} }