From 56e831b372a9f1e2f23379843d07e4a47b1b4d8c Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Thu, 30 May 2019 21:07:05 +0200 Subject: [PATCH] Implemented koya tiebreak --- src/Tiebreaks.php | 16 ++++++++++++++++ src/Tournament.php | 3 +++ 2 files changed, 19 insertions(+) diff --git a/src/Tiebreaks.php b/src/Tiebreaks.php index 3f4c8c7..11d7dcc 100644 --- a/src/Tiebreaks.php +++ b/src/Tiebreaks.php @@ -144,4 +144,20 @@ abstract class Tiebreaks extends Tournament $allratings = array_slice($allratings, $cut); return round(array_sum($allratings) / count($allratings)); } + + /** + * @param Player $player + * @param int $cut + * @return int + */ + protected function calculateKoya(Player $player, int $cut = 50) + { + $tiebreak = 0; + foreach ($player->getPairings() as $plkey=>$plpairing) { + if (($plpairing->getOpponent()->getNoOfWins() / count($plpairing->getOpponent()->getPairings()) * 100) >= $cut) { + $tiebreak += $plpairing->getOpponent()->getNoOfWins(); + } + } + return $tiebreak; + } } diff --git a/src/Tournament.php b/src/Tournament.php index 09e1107..1c8eac7 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -296,6 +296,9 @@ class Tournament extends Tiebreaks case Tiebreak::AroCut: return $this->calculateAverageRating($player, 1); break; + case Tiebreak::Koya: + return $this->calculateKoya($player); + break; default: return null; }