diff --git a/src/Tiebreaks.php b/src/Tiebreaks.php index 5f07958..19259a3 100644 --- a/src/Tiebreaks.php +++ b/src/Tiebreaks.php @@ -153,7 +153,7 @@ abstract class Tiebreaks extends Tournament protected function calculateKoya(Player $player, int $cut = 50) { $tiebreak = 0; - foreach ($player->getPairings() as $plkey=>$plpairing) { + foreach ($player->getPairings() as $plkey => $plpairing) { if (($plpairing->getOpponent()->getNoOfWins() / count($plpairing->getOpponent()->getPairings()) * 100) >= $cut) { $tiebreak += $plpairing->getOpponent()->getNoOfWins(); } @@ -183,9 +183,27 @@ abstract class Tiebreaks extends Tournament array_splice($intpairings, $cutlowest); array_splice($intpairings, 0 - $cuthighest); - foreach ($intpairings as $intkey=>$intpairing) { + foreach ($intpairings as $intkey => $intpairing) { $tiebreak += $intpairing->getOpponent()->getPoints(); } return $tiebreak; } + + + /** + * @param Player $player + * @return float|int|null + */ + protected function calculateSonneborn(Player $player) + { + $tiebreak = 0; + foreach ($player->getPairings() as $key => $pairing) { + if (array_search($pairing->getResult(), Constants::Won) !== false) { + $tiebreak += $pairing->getOpponent()->getPoints(); + } elseif (array_search($pairing->getResult(), Constants::draw) !== false) { + $tiebreak += $pairing->getOpponent()->getPoints() / 2; + } + } + return $tiebreak; + } } diff --git a/src/Tournament.php b/src/Tournament.php index bd735b4..0d468af 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -308,6 +308,9 @@ class Tournament extends Tiebreaks case Tiebreak::BuchholzMed: return $this->calculateBuchholz($player, 1, 1); break; + case Tiebreak::Sonneborn: + return $this->calculateSonneborn($player); + break; default: return null; }