From 07c3a8ad21dacabbd9cd0a10ec548ecf7a141c98 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Thu, 30 May 2019 21:20:14 +0200 Subject: [PATCH] Implemented kashdan --- src/Tiebreaks.php | 26 ++++++++++++++++++++++++++ src/Tournament.php | 3 +++ 2 files changed, 29 insertions(+) diff --git a/src/Tiebreaks.php b/src/Tiebreaks.php index 19259a3..5c308fd 100644 --- a/src/Tiebreaks.php +++ b/src/Tiebreaks.php @@ -206,4 +206,30 @@ abstract class Tiebreaks extends Tournament } return $tiebreak; } + + + /** + * @param Player $player + * @return int + */ + protected function calculateKashdan(Player $player) + { + $tiebreak = 0; + foreach ($player->getPairings() as $pairing) { + $toadd = 0; + if (array_search($pairing->getResult(), Constants::Won) !== false) { + $toadd = 3; + } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { + $toadd = 2; + } elseif (array_search($pairing->getResult(), Constants::Lost) !== false) { + $toadd = 1; + } + + if (array_search(Constants::NotPlayed, $pairing->getResult()) !== false) { + $toadd = 0; + } + $tiebreak += $toadd; + } + return $tiebreak; + } } diff --git a/src/Tournament.php b/src/Tournament.php index 0d468af..2f09001 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -311,6 +311,9 @@ class Tournament extends Tiebreaks case Tiebreak::Sonneborn: return $this->calculateSonneborn($player); break; + case Tiebreak::Kashdan: + return $this->calculateKashdan($player); + break; default: return null; }