diff --git a/src/Tiebreaks.php b/src/Tiebreaks.php index f5a1e0c..1670315 100644 --- a/src/Tiebreaks.php +++ b/src/Tiebreaks.php @@ -9,10 +9,10 @@ use JeroenED\Libpairtwo\Enums\Result; abstract class Tiebreaks extends Tournament { - private const Won = [ Result::won, Result::wonforfait, Result::wonbye, Result::wonadjourned ]; private const Draw = [ Result::draw, Result::drawadjourned]; private const Lost = [ Result::absent, Result::bye, Result::lost, Result::adjourned ]; + private const NotPlayed = [ Result::bye, Result::wonbye, Result::absent ]; private const Black = [ Color::black ]; private const White = [ Color::white ]; @@ -137,12 +137,24 @@ abstract class Tiebreaks extends Tournament return $points; } - protected function calculateAverageRating(Player $player) { + /** + * @param Player $player + * @return float + */ + protected function calculateAverageRating(Player $player) + { $pairings = $player->getPairings(); $totalrating = 0; - $opponents; + $totalopponents = 0; foreach ($pairings as $pairing) { - if ($pairing->getOpponent()->getElos['national']) + if (array_search($pairing->getResult(), self::NotPlayed) === false) { + $toadd = $pairing->getOpponent()->getElos()['home']; + if ($toadd != 0) { + $totalrating += $toadd; + $totalopponents++; + } + } } + return round($totalrating / $totalopponents); } } diff --git a/src/Tournament.php b/src/Tournament.php index b106839..6968a6c 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -290,6 +290,9 @@ class Tournament extends Tiebreaks case Tiebreak::Between: return $this->calculateMutualResult($player, $this->getPlayers(), $tbkey); break; + case Tiebreak::Aro: + return $this->calculateAverageRating($player); + break; default: return null; }