From 00c79b347c11073256dbf59d04f09f7d7ddca3aa Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Fri, 27 Sep 2019 16:27:04 +0200 Subject: [PATCH] Added function to calcultate buchholz score --- src/Player.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Player.php b/src/Player.php index 12d54e7..9876f21 100644 --- a/src/Player.php +++ b/src/Player.php @@ -192,7 +192,29 @@ class Player return $points; } - + /** + * Returns the points of the player that should be used for buchholz. + * + * 1 Point is awarded for winning + * 0.5 points are awarded for draw + * 0.5 points for not played + * + * @return float + */ + public function getPointsForBuchholz(): float + { + $points = 0; + foreach ($this->getPairings() as $pairing) { + if (array_search($pairing->getResult(), Constants::NotPlayed) !== false) { + $points = $points + 0.5; + } elseif (array_search($pairing->getResult(), Constants::Won) !== false) { + $points = $points + 1; + } elseif (array_search($pairing->getResult(), Constants::Draw) !== false) { + $points = $points + 0.5; + } + } + return $points; + } /** * Returns the performance rating of the player *