From 0179e52eb2b66fb336403a117a5c1ec396957472 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Thu, 30 May 2019 21:25:37 +0200 Subject: [PATCH] Added cumulative tiebreak --- src/Tiebreaks.php | 19 +++++++++++++++++++ src/Tournament.php | 3 +++ 2 files changed, 22 insertions(+) diff --git a/src/Tiebreaks.php b/src/Tiebreaks.php index 5c308fd..652b789 100644 --- a/src/Tiebreaks.php +++ b/src/Tiebreaks.php @@ -232,4 +232,23 @@ abstract class Tiebreaks extends Tournament } return $tiebreak; } + + /** + * @param Player $player + * @return float|int + */ + protected function calculateCumulative(Player $player) + { + $tiebreak = 0; + foreach ($player->getPairings() as $pairing) { + $toadd = 0; + if (array_search($pairing->getResult(), Constants::Won) !== false) { + $toadd = 1; + } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { + $toadd = 0.5; + } + $tiebreak += $tiebreak + $toadd; + } + return $tiebreak; + } } diff --git a/src/Tournament.php b/src/Tournament.php index 2f09001..9841ec8 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -314,6 +314,9 @@ class Tournament extends Tiebreaks case Tiebreak::Kashdan: return $this->calculateKashdan($player); break; + case Tiebreak::Cumulative: + return $this->calculateCumulative($player); + break; default: return null; }