mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-11-22 06:26:57 +01:00
BUGFIX: Buchholz score did not return the correct score
This commit is contained in:
parent
8483d2556c
commit
6e43f43a8d
@ -6,6 +6,7 @@
|
||||
* ENHANCEMENT: `Class::getBinaryData` methods return null if field is non-existent
|
||||
* CHANGE: `Tournament::getArbiter` accepts a `int` parameter representing the order of the arbiters
|
||||
* BUGFIX: `Player:GetId` returns elo instead of id
|
||||
* BUGFIX: `Tournament::CalculateBuchholz` did not return the correct score when player had onplayed rounds
|
||||
|
||||
## v1.1.2 (Release: 21-jun-2019)
|
||||
* ENHANCEMENT: Added update section to dist/readme.md
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -201,7 +201,7 @@ class Tournament
|
||||
|
||||
/**
|
||||
* Adds an arbiter to the tournament
|
||||
*
|
||||
*
|
||||
* @param string $Arbiter
|
||||
* @return Tournament
|
||||
*/
|
||||
@ -710,29 +710,40 @@ class Tournament
|
||||
private function calculateBuchholz(Player $player, int $cutlowest = 0, int $cuthighest = 0): ?float
|
||||
{
|
||||
$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) {
|
||||
if (is_null($a->getOpponent())) {
|
||||
return -1;
|
||||
}
|
||||
if (is_null($b->getOpponent())) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($b->getOpponent()->getPoints() == $a->getOpponent()->getPoints()) {
|
||||
if ($b == $a) {
|
||||
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, 0 - $cuthighest);
|
||||
|
||||
foreach ($intpairings as $intkey => $intpairing) {
|
||||
if (!is_null($intpairing->getOpponent())) {
|
||||
$tiebreak += $intpairing->getOpponent()->getPoints();
|
||||
}
|
||||
$tiebreak += $intpairing;
|
||||
}
|
||||
return $tiebreak;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user