Implemented buchholz

This commit is contained in:
Jeroen De Meerleer 2019-05-30 21:13:14 +02:00
parent 587a7a2e08
commit eba962a11c
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
2 changed files with 38 additions and 1 deletions

View File

@ -36,7 +36,7 @@ abstract class Tiebreaks extends Tournament
*/
protected function calculatePoints(Player $player): ?float
{
return $player->getPoints();
return $player->getPoints();
}
@ -160,4 +160,32 @@ abstract class Tiebreaks extends Tournament
}
return $tiebreak;
}
/**
* @param Player $player
* @param int $cutlowest
* @param int $cuthighest
* @return int
*/
protected function calculateBuchholz(Player $player, int $cutlowest = 0, int $cuthighest = 0)
{
$tiebreak = 0;
$intpairings = $player->getPairings();
usort($intpairings, function ($a, $b) {
if ($b->getOpponent()->getElo('home') == $a->getOpponent()->getElo('home')) {
return 0;
}
return ($b->getOpponent()->getElo('home') > $a->getOpponent()->getElo('home')) ? 1 : -1;
});
array_splice($intpairings, $cutlowest);
array_splice($intpairings, 0 - $cuthighest);
foreach ($intpairings as $intkey=>$intpairing) {
$tiebreak += $intpairing->getOpponent()->getPoints();
}
return $tiebreak;
}
}

View File

@ -299,6 +299,15 @@ class Tournament extends Tiebreaks
case Tiebreak::Koya:
return $this->calculateKoya($player);
break;
case Tiebreak::Buchholz:
return $this->calculateBuchholz($player);
break;
case Tiebreak::BuchholzCut:
return $this->calculateBuchholz($player, 1);
break;
case Tiebreak::BuchholzMed:
return $this->calculateBuchholz($player, 1, 1);
break;
default:
return null;
}