mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-12-23 21:00:58 +01:00
Compare commits
3 Commits
c3b2e840f7
...
c49ea32f08
Author | SHA1 | Date | |
---|---|---|---|
c49ea32f08 | |||
0f8721e57e | |||
ad86f962c5 |
@ -15,6 +15,7 @@ namespace JeroenED\Libpairtwo;
|
||||
|
||||
use DateTime;
|
||||
use JeroenED\Libpairtwo\Enums\Gender;
|
||||
use JeroenED\Libpairtwo\Enums\Result;
|
||||
use JeroenED\Libpairtwo\Enums\Title;
|
||||
|
||||
/**
|
||||
@ -227,15 +228,19 @@ class Player
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function calculatePoints(int $round = -1): float
|
||||
public function calculatePoints(int $round = -1, array $custompoints = []): float
|
||||
{
|
||||
$points = 0;
|
||||
foreach ($this->Pairings as $key => $pairing) {
|
||||
if ($key < $round || $round == -1) {
|
||||
if (array_search($pairing->Result, Constants::WON) !== false) {
|
||||
$points = $points + 1;
|
||||
if ($pairing->Result == Result::WON_BYE) {
|
||||
$points += (isset($this->CustomPoints[ 'bye' ])) ? $custompoints[ 'bye' ] : 1;
|
||||
} elseif (array_search($pairing->Result, Constants::WON) !== false) {
|
||||
$points += (isset($custompoints[ 'win' ])) ? $custompoints[ 'win' ] : 1;
|
||||
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
|
||||
$points = $points + 0.5;
|
||||
$points += (isset($custompoints[ 'draw' ])) ? $custompoints[ 'draw' ] : 0.5;
|
||||
} elseif (array_search($pairing->Result, Constants::LOST) !== false) {
|
||||
$points += (isset($custompoints[ 'loss' ])) ? $custompoints[ 'loss' ] : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -242,21 +242,36 @@ class Swar5 implements ReaderInterface
|
||||
|
||||
$this->Tournament->FideHomol = $this->readData('Int', $swshandle);
|
||||
|
||||
$this->Tournament->FideId = $this->readData('String', $swshandle);
|
||||
if (version_compare($this->Release, '5.24', ">=")) {
|
||||
$this->Tournament->FideId = $this->readData('Int', $swshandle);
|
||||
} else {
|
||||
for ($i = 0; $i <= 15; $i++) {
|
||||
// First round
|
||||
$this->readData('Int', $swshandle);
|
||||
//last round
|
||||
$this->readData('Int', $swshandle);
|
||||
//fide ID
|
||||
$this->readData('Int', $swshandle);
|
||||
}
|
||||
}
|
||||
$this->Tournament->FideArbitre1 = $this->readData('String', $swshandle);
|
||||
$this->Tournament->FideArbitre2 = $this->readData('String', $swshandle);
|
||||
$this->Tournament->FideEmail = $this->readData('String', $swshandle);
|
||||
$this->Tournament->FideRemarques = $this->readData('String', $swshandle);
|
||||
|
||||
$applycustompoints = false;
|
||||
switch ($this->readData('Int', $swshandle)) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
default:
|
||||
$system = TournamentSystem::SWISS;
|
||||
break;
|
||||
case 4:
|
||||
$applycustompoints = true;
|
||||
$system = TournamentSystem::SWISS;
|
||||
break;
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
@ -274,11 +289,12 @@ class Swar5 implements ReaderInterface
|
||||
$this->Tournament->SW_AmerPresence = $this->readData('Int', $swshandle);
|
||||
$this->Tournament->Plusieurs = $this->readData('Int', $swshandle);
|
||||
$this->Tournament->FirstTable = $this->readData('Int', $swshandle);
|
||||
$this->Tournament->SW321_Win = $this->readData('Int', $swshandle);
|
||||
$this->Tournament->SW321_Nul = $this->readData('Int', $swshandle);
|
||||
$this->Tournament->SW321_Los = $this->readData('Int', $swshandle);
|
||||
$this->Tournament->SW321_Bye = $this->readData('Int', $swshandle);
|
||||
$this->Tournament->SW321_Pre = $this->readData('Int', $swshandle);
|
||||
$custompoints['win'] = $this->readData('Int', $swshandle) / 4;
|
||||
$custompoints['draw'] = $this->readData('Int', $swshandle) / 4;
|
||||
$custompoints['loss'] = $this->readData('Int', $swshandle) / 4;
|
||||
$custompoints['bye'] = $this->readData('Int', $swshandle) / 4;
|
||||
$custompoints['absent'] = $this->readData('Int', $swshandle) / 4;
|
||||
if($applycustompoints) $this->Tournament->CustomPoints = $custompoints;
|
||||
$this->Tournament->EloUsed = $this->readData('Int', $swshandle);
|
||||
$this->Tournament->TournoiStd = $this->readData('Int', $swshandle);
|
||||
$this->Tournament->TbPersonel = $this->readData('Int', $swshandle);
|
||||
|
@ -204,6 +204,13 @@ class Tournament
|
||||
*/
|
||||
public $Tiebreaks = [];
|
||||
|
||||
/**
|
||||
* Custom points for the tournament
|
||||
*
|
||||
* @var float[]
|
||||
*/
|
||||
public $CustomPoints = ['win' => 1, 'draw' => 0.5, 'loss' => 0, 'bye' => 1, 'absent' => 0];
|
||||
|
||||
/**
|
||||
* The year or season the tournament is held or is count for
|
||||
*
|
||||
@ -698,7 +705,7 @@ class Tournament
|
||||
*/
|
||||
private function calculatePoints(Player $player): float
|
||||
{
|
||||
return $player->calculatePoints();
|
||||
return $player->calculatePoints(-1, $this->CustomPoints);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user