BUGFIX: Sonneborn-berger did not use a virtual opponent

This commit is contained in:
Jeroen De Meerleer 2019-12-22 18:17:17 +01:00
parent f8c8945180
commit 3926b9738b
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
4 changed files with 47 additions and 33 deletions

2
dist/template.php vendored
View File

@ -2,7 +2,7 @@
// EDIT ME! // EDIT ME!
$pairingfile = 'your pairing-file.swar'; $pairingfile = 'your pairing-file.swar';
$fileformat = 'Swar-4'; // Possible getValue()s: Pairtwo-5, Pairtwo-6, Swar-4 $fileformat = 'Swar-4'; // Possible values: Pairtwo-5, Pairtwo-6, Swar-4
?> ?>
<!doctype html> <!doctype html>

View File

@ -211,28 +211,49 @@ class Player
} }
/** /**
* Returns the points of the player. * Returns the points of the player after round $round
* *
* 1 Point is awarded for winning * 1 Point is awarded for winning
* 0.5 points are awarded for draw * 0.5 points are awarded for draw
* 0 points are awarded for loss
* *
* @param int $round
* @return float * @return float
*/ */
public function calculatePoints(): float public function calculatePoints(int $round = -1): float
{ {
$points = 0; $points = 0;
foreach ($this->Pairings as $pairing) { foreach ($this->Pairings as $key=>$pairing) {
if (array_search($pairing->Result, Constants::Won) !== false) { if ($key < $round || $round == -1) {
$points = $points + 1; if (array_search($pairing->Result, Constants::Won) !== false) {
} elseif (array_search($pairing->Result, Constants::Draw) !== false) { $points = $points + 1;
$points = $points + 0.5; } elseif (array_search($pairing->Result, Constants::Draw) !== false) {
$points = $points + 0.5;
}
} }
} }
return $points; return $points;
} }
/** /**
* Returns the points of the player that should be used for buchholz. * Returns the points of a virtual player as described in the Fide Handbook C.02 chapter 13.15.2.
*
* 1 Point is awarded for winning
* 0.5 points are awarded for draw
* Unplayed results are conside
*
* @return float
*/
public function calculatePointsForVirtualPlayer(int $byeround): float
{
$points = $this->calculatePoints($byeround);
foreach (array_slice($this->Pairings, $byeround +1) as $key=>$pairing) {
$points += 0.5;
}
return $points;
}
/**
* Returns the points of the player that should be used for tiebreaking systems.
* *
* 1 Point is awarded for winning * 1 Point is awarded for winning
* 0.5 points are awarded for draw * 0.5 points are awarded for draw
@ -240,7 +261,7 @@ class Player
* *
* @return float * @return float
*/ */
private function pointsForBuchholz(): float public function calculatePointsForTiebreaks(): float
{ {
$points = 0; $points = 0;
foreach ($this->Pairings as $pairing) { foreach ($this->Pairings as $pairing) {
@ -309,12 +330,10 @@ class Player
*/ */
public function __get(string $key) public function __get(string $key)
{ {
if($key == 'PlayedGames') { if ($key == 'PlayedGames') {
return $this->playedGames(); return $this->playedGames();
} elseif ($key == 'NoOfWins') { } elseif ($key == 'NoOfWins') {
return $this->noOfWins(); return $this->noOfWins();
} elseif ($key == 'PointsForBuchholz') {
return $this->pointsForBuchholz();
} elseif (isset($this->BinaryData[$key])) { } elseif (isset($this->BinaryData[$key])) {
return $this->BinaryData[$key]; return $this->BinaryData[$key];
} }

View File

@ -150,14 +150,11 @@ class Round
{ {
if ($key == 'Bye') { if ($key == 'Bye') {
return $this->bye(); return $this->bye();
} } elseif ($key == 'Absent') {
elseif ($key == 'Absent') {
return $this->absent(); return $this->absent();
} } elseif ($key == 'GamesByBoard') {
elseif ($key == 'GamesByBoard') {
return $this->gamesByBoard(); return $this->gamesByBoard();
} } elseif (isset($this->BinaryData[$key])) {
elseif (isset($this->BinaryData[$key])) {
return $this->BinaryData[$key]; return $this->BinaryData[$key];
} }
return null; return null;

View File

@ -197,7 +197,7 @@ class Tournament
/** /**
* Binary data that was read out of the pairing file * Binary data that was read out of the pairing file
* *
* @var bool|DateTime|int|string[] * @var bool|DateTime|int|string[]
*/ */
private $BinaryData = []; private $BinaryData = [];
@ -813,14 +813,12 @@ class Tournament
$intpairings = []; $intpairings = [];
$curpoints = 0; $curpoints = 0;
$curround = 1; $curround = 1;
foreach ($intpairingsWithBye as $pairing) { foreach ($intpairingsWithBye as $key=>$pairing) {
$roundstoplay = (count($intpairingsWithBye)) - $curround; $roundstoplay = (count($intpairingsWithBye)) - $curround;
if (is_null($pairing->Opponent)) { if (is_null($pairing->Opponent)) {
$forfait = explode(' ', $pairing->Result)[0]+0; $intpairings[] = $player->calculatePointsForVirtualPlayer($key);
$notaplayer = $curpoints + (1 - $forfait) + 0.5 * $roundstoplay;
$intpairings[] = $notaplayer;
} else { } else {
$intpairings[] = $pairing->Opponent->PointsForBuchholz; $intpairings[] = $pairing->Opponent->calculatePointsForTiebreaks();
if (array_search($pairing->Result, Constants::Won) !== false) { if (array_search($pairing->Result, Constants::Won) !== false) {
$curpoints += 1; $curpoints += 1;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) { } elseif (array_search($pairing->Result, Constants::Draw) !== false) {
@ -856,11 +854,14 @@ class Tournament
foreach ($player->Pairings as $key => $pairing) { foreach ($player->Pairings as $key => $pairing) {
if ($pairing->Opponent) { if ($pairing->Opponent) {
if (array_search($pairing->Result, Constants::Won) !== false) { if (array_search($pairing->Result, Constants::Won) !== false) {
$tiebreak += $pairing->Opponent->calculatePoints(); $tiebreak += $pairing->Opponent->calculatePointsForTiebreaks();
} elseif (array_search($pairing->Result, Constants::Draw) !== false) { } elseif (array_search($pairing->Result, Constants::Draw) !== false) {
$tiebreak += $pairing->Opponent->calculatePoints() / 2; $tiebreak += $pairing->Opponent->calculatePointsForTiebreaks() / 2;
} }
} }
if (array_search($pairing->Result, Constants::NotPlayed) !== false) {
$tiebreak += $player->calculatePointsForVirtualPlayer($key);
}
} }
return $tiebreak; return $tiebreak;
} }
@ -927,14 +928,11 @@ class Tournament
{ {
if ($key == 'Participants') { if ($key == 'Participants') {
return $this->participants(); return $this->participants();
} } elseif ($key == 'AverageElo') {
elseif ($key == 'AverageElo') {
return $this->averageElo(); return $this->averageElo();
} } elseif ($key == 'Ranking') {
elseif ($key == 'Ranking') {
return $this->ranking(); return $this->ranking();
} } elseif (isset($this->BinaryData[$key])) {
elseif (isset($this->BinaryData[$key])) {
return $this->BinaryData[$key]; return $this->BinaryData[$key];
} }
return null; return null;