Implemented Sonneborn-Berger

This commit is contained in:
Jeroen De Meerleer 2019-05-30 21:16:12 +02:00
parent eba962a11c
commit 5128d2762e
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
2 changed files with 23 additions and 2 deletions

View File

@ -188,4 +188,22 @@ abstract class Tiebreaks extends Tournament
}
return $tiebreak;
}
/**
* @param Player $player
* @return float|int|null
*/
protected function calculateSonneborn(Player $player)
{
$tiebreak = 0;
foreach ($player->getPairings() as $key => $pairing) {
if (array_search($pairing->getResult(), Constants::Won) !== false) {
$tiebreak += $pairing->getOpponent()->getPoints();
} elseif (array_search($pairing->getResult(), Constants::draw) !== false) {
$tiebreak += $pairing->getOpponent()->getPoints() / 2;
}
}
return $tiebreak;
}
}

View File

@ -308,6 +308,9 @@ class Tournament extends Tiebreaks
case Tiebreak::BuchholzMed:
return $this->calculateBuchholz($player, 1, 1);
break;
case Tiebreak::Sonneborn:
return $this->calculateSonneborn($player);
break;
default:
return null;
}