mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-11-22 06:26:57 +01:00
Reimplemented buchholz score
Ref: FRBE-KBSB Vademecum in dutch page 143 and 145-146
This commit is contained in:
parent
00c79b347c
commit
95aab15a58
@ -201,7 +201,7 @@ class Tournament
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an arbiter to the tournament
|
* Adds an arbiter to the tournament
|
||||||
*
|
*
|
||||||
* @param string $Arbiter
|
* @param string $Arbiter
|
||||||
* @return Tournament
|
* @return Tournament
|
||||||
*/
|
*/
|
||||||
@ -710,29 +710,40 @@ class Tournament
|
|||||||
private function calculateBuchholz(Player $player, int $cutlowest = 0, int $cuthighest = 0): ?float
|
private function calculateBuchholz(Player $player, int $cutlowest = 0, int $cuthighest = 0): ?float
|
||||||
{
|
{
|
||||||
$tiebreak = 0;
|
$tiebreak = 0;
|
||||||
$intpairings = $player->getPairings();
|
$intpairingsWithBye = $player->getPairings();
|
||||||
|
|
||||||
|
$intpairings = [];
|
||||||
|
$curpoints = 0;
|
||||||
|
$curround = 1;
|
||||||
|
foreach ($intpairingsWithBye as $pairing) {
|
||||||
|
$roundstoplay = (count($intpairingsWithBye)) - $curround;
|
||||||
|
if (is_null($pairing->getOpponent())) {
|
||||||
|
$forfait = explode(' ', $pairing->getResult())[0]+0;
|
||||||
|
$notaplayer = $curpoints + (1 - $forfait) + 0.5 * $roundstoplay;
|
||||||
|
$intpairings[] = $notaplayer;
|
||||||
|
} else {
|
||||||
|
$intpairings[] = $pairing->getOpponent()->getPointsForBuchholz();
|
||||||
|
if (array_search($pairing->getResult(), Constants::Won) !== false) {
|
||||||
|
$curpoints += 1;
|
||||||
|
} elseif (array_search($pairing->getResult(), Constants::Draw) !== false) {
|
||||||
|
$curpoints += 0.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$curround++;
|
||||||
|
}
|
||||||
|
|
||||||
usort($intpairings, function ($a, $b) {
|
usort($intpairings, function ($a, $b) {
|
||||||
if (is_null($a->getOpponent())) {
|
if ($b == $a) {
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (is_null($b->getOpponent())) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($b->getOpponent()->getPoints() == $a->getOpponent()->getPoints()) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return ($a->getOpponent()->getPoints() > $b->getOpponent()->getPoints()) ? 1 : -1;
|
return ($a > $b) ? 1 : -1;
|
||||||
});
|
});
|
||||||
|
|
||||||
$intpairings = array_slice($intpairings, $cutlowest);
|
$intpairings = array_slice($intpairings, $cutlowest);
|
||||||
$intpairings = array_slice($intpairings, 0 - $cuthighest);
|
$intpairings = array_slice($intpairings, 0 - $cuthighest);
|
||||||
|
|
||||||
foreach ($intpairings as $intkey => $intpairing) {
|
foreach ($intpairings as $intkey => $intpairing) {
|
||||||
if (!is_null($intpairing->getOpponent())) {
|
$tiebreak += $intpairing;
|
||||||
$tiebreak += $intpairing->getOpponent()->getPoints();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $tiebreak;
|
return $tiebreak;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user