mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-11-27 00:37:42 +01:00
BUGFIX: Sonneborn-berger did not use a virtual opponent
This commit is contained in:
parent
f8c8945180
commit
3926b9738b
2
dist/template.php
vendored
2
dist/template.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// EDIT ME!
|
||||
$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>
|
||||
|
@ -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
|
||||
* 0.5 points are awarded for draw
|
||||
* 0 points are awarded for loss
|
||||
*
|
||||
* @param int $round
|
||||
* @return float
|
||||
*/
|
||||
public function calculatePoints(): float
|
||||
public function calculatePoints(int $round = -1): float
|
||||
{
|
||||
$points = 0;
|
||||
foreach ($this->Pairings as $pairing) {
|
||||
if (array_search($pairing->Result, Constants::Won) !== false) {
|
||||
$points = $points + 1;
|
||||
} elseif (array_search($pairing->Result, Constants::Draw) !== false) {
|
||||
$points = $points + 0.5;
|
||||
foreach ($this->Pairings as $key=>$pairing) {
|
||||
if ($key < $round || $round == -1) {
|
||||
if (array_search($pairing->Result, Constants::Won) !== false) {
|
||||
$points = $points + 1;
|
||||
} elseif (array_search($pairing->Result, Constants::Draw) !== false) {
|
||||
$points = $points + 0.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
* 0.5 points are awarded for draw
|
||||
@ -240,7 +261,7 @@ class Player
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
private function pointsForBuchholz(): float
|
||||
public function calculatePointsForTiebreaks(): float
|
||||
{
|
||||
$points = 0;
|
||||
foreach ($this->Pairings as $pairing) {
|
||||
@ -309,12 +330,10 @@ class Player
|
||||
*/
|
||||
public function __get(string $key)
|
||||
{
|
||||
if($key == 'PlayedGames') {
|
||||
if ($key == 'PlayedGames') {
|
||||
return $this->playedGames();
|
||||
} elseif ($key == 'NoOfWins') {
|
||||
return $this->noOfWins();
|
||||
} elseif ($key == 'PointsForBuchholz') {
|
||||
return $this->pointsForBuchholz();
|
||||
} elseif (isset($this->BinaryData[$key])) {
|
||||
return $this->BinaryData[$key];
|
||||
}
|
||||
|
@ -150,14 +150,11 @@ class Round
|
||||
{
|
||||
if ($key == 'Bye') {
|
||||
return $this->bye();
|
||||
}
|
||||
elseif ($key == 'Absent') {
|
||||
} elseif ($key == 'Absent') {
|
||||
return $this->absent();
|
||||
}
|
||||
elseif ($key == 'GamesByBoard') {
|
||||
} elseif ($key == 'GamesByBoard') {
|
||||
return $this->gamesByBoard();
|
||||
}
|
||||
elseif (isset($this->BinaryData[$key])) {
|
||||
} elseif (isset($this->BinaryData[$key])) {
|
||||
return $this->BinaryData[$key];
|
||||
}
|
||||
return null;
|
||||
|
@ -197,7 +197,7 @@ class Tournament
|
||||
|
||||
/**
|
||||
* Binary data that was read out of the pairing file
|
||||
*
|
||||
*
|
||||
* @var bool|DateTime|int|string[]
|
||||
*/
|
||||
private $BinaryData = [];
|
||||
@ -813,14 +813,12 @@ class Tournament
|
||||
$intpairings = [];
|
||||
$curpoints = 0;
|
||||
$curround = 1;
|
||||
foreach ($intpairingsWithBye as $pairing) {
|
||||
foreach ($intpairingsWithBye as $key=>$pairing) {
|
||||
$roundstoplay = (count($intpairingsWithBye)) - $curround;
|
||||
if (is_null($pairing->Opponent)) {
|
||||
$forfait = explode(' ', $pairing->Result)[0]+0;
|
||||
$notaplayer = $curpoints + (1 - $forfait) + 0.5 * $roundstoplay;
|
||||
$intpairings[] = $notaplayer;
|
||||
$intpairings[] = $player->calculatePointsForVirtualPlayer($key);
|
||||
} else {
|
||||
$intpairings[] = $pairing->Opponent->PointsForBuchholz;
|
||||
$intpairings[] = $pairing->Opponent->calculatePointsForTiebreaks();
|
||||
if (array_search($pairing->Result, Constants::Won) !== false) {
|
||||
$curpoints += 1;
|
||||
} elseif (array_search($pairing->Result, Constants::Draw) !== false) {
|
||||
@ -856,11 +854,14 @@ class Tournament
|
||||
foreach ($player->Pairings as $key => $pairing) {
|
||||
if ($pairing->Opponent) {
|
||||
if (array_search($pairing->Result, Constants::Won) !== false) {
|
||||
$tiebreak += $pairing->Opponent->calculatePoints();
|
||||
$tiebreak += $pairing->Opponent->calculatePointsForTiebreaks();
|
||||
} 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;
|
||||
}
|
||||
@ -927,14 +928,11 @@ class Tournament
|
||||
{
|
||||
if ($key == 'Participants') {
|
||||
return $this->participants();
|
||||
}
|
||||
elseif ($key == 'AverageElo') {
|
||||
} elseif ($key == 'AverageElo') {
|
||||
return $this->averageElo();
|
||||
}
|
||||
elseif ($key == 'Ranking') {
|
||||
} elseif ($key == 'Ranking') {
|
||||
return $this->ranking();
|
||||
}
|
||||
elseif (isset($this->BinaryData[$key])) {
|
||||
} elseif (isset($this->BinaryData[$key])) {
|
||||
return $this->BinaryData[$key];
|
||||
}
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user