mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-12-22 04:11:22 +01:00
Implemented buchholz
This commit is contained in:
parent
587a7a2e08
commit
eba962a11c
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user