From 2eb570ce7cd9a534c04374cbf98b99f148312ac4 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Sat, 28 Sep 2019 20:54:59 +0200 Subject: [PATCH] Implemented setting board if not set yet --- src/Tournament.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Tournament.php b/src/Tournament.php index efce818..a9196c9 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -226,6 +226,10 @@ class Tournament /** @var Pairing[] */ $cache = array(); + /** @var int[] */ + $lastboards; + + /** @var Pairing $pairing */ foreach ($pairings as $pairing) { // Add pairing to player $pairing->getPlayer()->addPairing($pairing); @@ -234,6 +238,11 @@ class Tournament $this->getRoundByNo($round)->addPairing($pairing); $opponent = null; + + /** + * @var int $key + * @var Pairing $cached + */ foreach ($cache as $key=>$cached) { if (!is_null($cached)) { if (($cached->getOpponent() == $pairing->getPlayer()) && ($cached->getRound() == $pairing->getRound())) { @@ -257,6 +266,18 @@ class Tournament } else { // Check if game already exists 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); } }