Implemented Sonneborn-Berger

This commit is contained in:
Jeroen De Meerleer 2019-05-30 21:16:12 +02:00
parent eba962a11c
commit 5128d2762e
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
2 changed files with 23 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -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;
}