mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-12-23 12:50:59 +01:00
Fixed mutual result tiebreak
This commit is contained in:
parent
6f78b4ebe1
commit
82baae976e
@ -322,6 +322,43 @@ class Player
|
||||
return $total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if player has played against all players of the array
|
||||
*
|
||||
* @param Player[] $players
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPlayedAllPlayersOfArray(array $players): bool
|
||||
{
|
||||
$ownkey = array_search($this, $players);
|
||||
if ($ownkey !== false) {
|
||||
unset($players[$ownkey]);
|
||||
}
|
||||
$total = 0;
|
||||
foreach ($players as $player) {
|
||||
if (array_search($player, $this->Opponents) !== false) {
|
||||
$total++;
|
||||
}
|
||||
}
|
||||
|
||||
return $total == count($players);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all opponents of $this
|
||||
*
|
||||
* @return Player[]
|
||||
*/
|
||||
private function opponents() {
|
||||
$return = array();
|
||||
foreach ($this->Pairings as $pairing) {
|
||||
if (!empty($pairing->Opponent)) {
|
||||
$return[] = $pairing->Opponent;
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to read out several fields. If field was not found it is being searched in the binary data fields
|
||||
*
|
||||
@ -334,6 +371,8 @@ class Player
|
||||
return $this->playedGames();
|
||||
} elseif ($key == 'NoOfWins') {
|
||||
return $this->noOfWins();
|
||||
} elseif ($key == 'Opponents') {
|
||||
return $this->opponents();
|
||||
} elseif (isset($this->BinaryData[$key])) {
|
||||
return $this->BinaryData[$key];
|
||||
}
|
||||
|
@ -700,6 +700,15 @@ class Tournament
|
||||
}
|
||||
}
|
||||
}
|
||||
if($interestingplayers) {
|
||||
$allintplayers = $interestingplayers;
|
||||
$allintplayers[] = $player;
|
||||
foreach($allintplayers as $player) {
|
||||
if (!$player->hasPlayedAllPlayersOfArray($allintplayers)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
$points = 0;
|
||||
$totalmatches = 0;
|
||||
foreach ($player->Pairings as $pairing) {
|
||||
|
Loading…
Reference in New Issue
Block a user