From 91ea4c7a644a583759a62efd66d3dd152347ba2f Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Mon, 3 Jun 2019 12:30:14 +0200 Subject: [PATCH] Reimplemented official kashdan tiebreak --- src/Tiebreaks.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Tiebreaks.php b/src/Tiebreaks.php index e4f8778..00f455f 100644 --- a/src/Tiebreaks.php +++ b/src/Tiebreaks.php @@ -251,7 +251,7 @@ abstract class Tiebreaks extends Tournament * @param Player $player * @return float|null */ - protected function calculateKashdan(Player $player): ?float + protected function calculateSoccerKashdan(Player $player): ?float { $tiebreak = 0; foreach ($player->getPairings() as $pairing) { @@ -272,6 +272,32 @@ abstract class Tiebreaks extends Tournament return $tiebreak; // - $player->getNoOfWins(); } + + /** + * @param Player $player + * @return float|null + */ + protected function calculateKashdan(Player $player): ?float + { + $tiebreak = 0; + foreach ($player->getPairings() as $pairing) { + $toadd = 0; + if (array_search($pairing->getResult(), Constants::Won) !== false) { + $toadd = 4; + } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { + $toadd = 2; + } elseif (array_search($pairing->getResult(), Constants::Lost) !== false) { + $toadd = 1; + } + + if (array_search($pairing->getResult(), Constants::NotPlayed) !== false) { + $toadd = 0; + } + $tiebreak += $toadd; + } + return $tiebreak; // - $player->getNoOfWins(); + } + /** * @param Player $player * @return float|null