mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-11-22 06:26:57 +01:00
Implemented buchholz
This commit is contained in:
parent
587a7a2e08
commit
eba962a11c
@ -160,4 +160,32 @@ abstract class Tiebreaks extends Tournament
|
|||||||
}
|
}
|
||||||
return $tiebreak;
|
return $tiebreak;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Player $player
|
||||||
|
* @param int $cutlowest
|
||||||
|
* @param int $cuthighest
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
protected function calculateBuchholz(Player $player, int $cutlowest = 0, int $cuthighest = 0)
|
||||||
|
{
|
||||||
|
$tiebreak = 0;
|
||||||
|
$intpairings = $player->getPairings();
|
||||||
|
|
||||||
|
usort($intpairings, function ($a, $b) {
|
||||||
|
if ($b->getOpponent()->getElo('home') == $a->getOpponent()->getElo('home')) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return ($b->getOpponent()->getElo('home') > $a->getOpponent()->getElo('home')) ? 1 : -1;
|
||||||
|
});
|
||||||
|
|
||||||
|
array_splice($intpairings, $cutlowest);
|
||||||
|
array_splice($intpairings, 0 - $cuthighest);
|
||||||
|
|
||||||
|
foreach ($intpairings as $intkey=>$intpairing) {
|
||||||
|
$tiebreak += $intpairing->getOpponent()->getPoints();
|
||||||
|
}
|
||||||
|
return $tiebreak;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -299,6 +299,15 @@ class Tournament extends Tiebreaks
|
|||||||
case Tiebreak::Koya:
|
case Tiebreak::Koya:
|
||||||
return $this->calculateKoya($player);
|
return $this->calculateKoya($player);
|
||||||
break;
|
break;
|
||||||
|
case Tiebreak::Buchholz:
|
||||||
|
return $this->calculateBuchholz($player);
|
||||||
|
break;
|
||||||
|
case Tiebreak::BuchholzCut:
|
||||||
|
return $this->calculateBuchholz($player, 1);
|
||||||
|
break;
|
||||||
|
case Tiebreak::BuchholzMed:
|
||||||
|
return $this->calculateBuchholz($player, 1, 1);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user