diff --git a/dist/template.php b/dist/template.php index 4ae1cb2..9cd3e19 100644 --- a/dist/template.php +++ b/dist/template.php @@ -2,7 +2,7 @@ // EDIT ME! $pairingfile = 'your pairing-file.swar'; -$fileformat = 'Swar-4'; // Possible getValue()s: Pairtwo-5, Pairtwo-6, Swar-4 +$fileformat = 'Swar-4'; // Possible values: Pairtwo-5, Pairtwo-6, Swar-4 ?> diff --git a/src/Player.php b/src/Player.php index 414805c..bab5452 100644 --- a/src/Player.php +++ b/src/Player.php @@ -211,28 +211,49 @@ class Player } /** - * Returns the points of the player. + * Returns the points of the player after round $round * * 1 Point is awarded for winning * 0.5 points are awarded for draw + * 0 points are awarded for loss * + * @param int $round * @return float */ - public function calculatePoints(): float + public function calculatePoints(int $round = -1): float { $points = 0; - foreach ($this->Pairings as $pairing) { - if (array_search($pairing->Result, Constants::Won) !== false) { - $points = $points + 1; - } elseif (array_search($pairing->Result, Constants::Draw) !== false) { - $points = $points + 0.5; + foreach ($this->Pairings as $key=>$pairing) { + if ($key < $round || $round == -1) { + if (array_search($pairing->Result, Constants::Won) !== false) { + $points = $points + 1; + } elseif (array_search($pairing->Result, Constants::Draw) !== false) { + $points = $points + 0.5; + } } } return $points; } /** - * Returns the points of the player that should be used for buchholz. + * Returns the points of a virtual player as described in the Fide Handbook C.02 chapter 13.15.2. + * + * 1 Point is awarded for winning + * 0.5 points are awarded for draw + * Unplayed results are conside + * + * @return float + */ + public function calculatePointsForVirtualPlayer(int $byeround): float + { + $points = $this->calculatePoints($byeround); + foreach (array_slice($this->Pairings, $byeround +1) as $key=>$pairing) { + $points += 0.5; + } + return $points; + } + /** + * Returns the points of the player that should be used for tiebreaking systems. * * 1 Point is awarded for winning * 0.5 points are awarded for draw @@ -240,7 +261,7 @@ class Player * * @return float */ - private function pointsForBuchholz(): float + public function calculatePointsForTiebreaks(): float { $points = 0; foreach ($this->Pairings as $pairing) { @@ -309,12 +330,10 @@ class Player */ public function __get(string $key) { - if($key == 'PlayedGames') { + if ($key == 'PlayedGames') { return $this->playedGames(); } elseif ($key == 'NoOfWins') { return $this->noOfWins(); - } elseif ($key == 'PointsForBuchholz') { - return $this->pointsForBuchholz(); } elseif (isset($this->BinaryData[$key])) { return $this->BinaryData[$key]; } diff --git a/src/Round.php b/src/Round.php index 949872d..910218e 100644 --- a/src/Round.php +++ b/src/Round.php @@ -150,14 +150,11 @@ class Round { if ($key == 'Bye') { return $this->bye(); - } - elseif ($key == 'Absent') { + } elseif ($key == 'Absent') { return $this->absent(); - } - elseif ($key == 'GamesByBoard') { + } elseif ($key == 'GamesByBoard') { return $this->gamesByBoard(); - } - elseif (isset($this->BinaryData[$key])) { + } elseif (isset($this->BinaryData[$key])) { return $this->BinaryData[$key]; } return null; diff --git a/src/Tournament.php b/src/Tournament.php index b0cb249..ebacb50 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -197,7 +197,7 @@ class Tournament /** * Binary data that was read out of the pairing file - * + * * @var bool|DateTime|int|string[] */ private $BinaryData = []; @@ -813,14 +813,12 @@ class Tournament $intpairings = []; $curpoints = 0; $curround = 1; - foreach ($intpairingsWithBye as $pairing) { + foreach ($intpairingsWithBye as $key=>$pairing) { $roundstoplay = (count($intpairingsWithBye)) - $curround; if (is_null($pairing->Opponent)) { - $forfait = explode(' ', $pairing->Result)[0]+0; - $notaplayer = $curpoints + (1 - $forfait) + 0.5 * $roundstoplay; - $intpairings[] = $notaplayer; + $intpairings[] = $player->calculatePointsForVirtualPlayer($key); } else { - $intpairings[] = $pairing->Opponent->PointsForBuchholz; + $intpairings[] = $pairing->Opponent->calculatePointsForTiebreaks(); if (array_search($pairing->Result, Constants::Won) !== false) { $curpoints += 1; } elseif (array_search($pairing->Result, Constants::Draw) !== false) { @@ -856,11 +854,14 @@ class Tournament foreach ($player->Pairings as $key => $pairing) { if ($pairing->Opponent) { if (array_search($pairing->Result, Constants::Won) !== false) { - $tiebreak += $pairing->Opponent->calculatePoints(); + $tiebreak += $pairing->Opponent->calculatePointsForTiebreaks(); } elseif (array_search($pairing->Result, Constants::Draw) !== false) { - $tiebreak += $pairing->Opponent->calculatePoints() / 2; + $tiebreak += $pairing->Opponent->calculatePointsForTiebreaks() / 2; } } + if (array_search($pairing->Result, Constants::NotPlayed) !== false) { + $tiebreak += $player->calculatePointsForVirtualPlayer($key); + } } return $tiebreak; } @@ -927,14 +928,11 @@ class Tournament { if ($key == 'Participants') { return $this->participants(); - } - elseif ($key == 'AverageElo') { + } elseif ($key == 'AverageElo') { return $this->averageElo(); - } - elseif ($key == 'Ranking') { + } elseif ($key == 'Ranking') { return $this->ranking(); - } - elseif (isset($this->BinaryData[$key])) { + } elseif (isset($this->BinaryData[$key])) { return $this->BinaryData[$key]; } return null;