mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-11-24 23:37:41 +01:00
Merge branch 'task/reader/swar' into develop
This commit is contained in:
commit
52079b60bc
@ -33,6 +33,8 @@ class Tiebreak extends Enum
|
||||
const Buchholz = "Buchholz";
|
||||
const BuchholzMed = "Buchholz Median";
|
||||
const BuchholzCut = "Buchholz Cut";
|
||||
const BuchholzMed2 = "Buchholz Median 2";
|
||||
const BuchholzCut2 = "Buchholz Cut 2";
|
||||
const Sonneborn = "Sonneborn-Berger";
|
||||
const Kashdan = "Kashdan";
|
||||
const SoccerKashdan = "Soccer Kashdan";
|
||||
|
@ -15,6 +15,7 @@ namespace JeroenED\Libpairtwo\Readers;
|
||||
|
||||
use DateTime;
|
||||
use JeroenED\Libpairtwo\Enums\Color;
|
||||
use JeroenED\Libpairtwo\Enums\Tiebreak;
|
||||
use JeroenED\Libpairtwo\Enums\TournamentSystem;
|
||||
use JeroenED\Libpairtwo\Exceptions\IncompatibleReaderException;
|
||||
use JeroenED\Libpairtwo\Interfaces\ReaderInterface;
|
||||
@ -234,9 +235,62 @@ class Swar4 implements ReaderInterface
|
||||
|
||||
$this->getTournament()->setBinaryData('[TIE_BREAK]', $this->readData('String', $swshandle));
|
||||
|
||||
$tiebreaks = [];
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$this->getTournament()->setBinaryData('Tiebreak_' . $i, $this->readData('Int', $swshandle));
|
||||
switch($this->readData('Int', $swshandle)) {
|
||||
case 0:
|
||||
default:
|
||||
$tiebreak = Tiebreak::None;
|
||||
break;
|
||||
case 1:
|
||||
$tiebreak = Tiebreak::Buchholz;
|
||||
break;
|
||||
case 2:
|
||||
$tiebreak = Tiebreak::BuchholzMed;
|
||||
break;
|
||||
case 3:
|
||||
$tiebreak = Tiebreak::BuchholzMed2;
|
||||
break;
|
||||
case 4:
|
||||
$tiebreak = Tiebreak::BuchholzCut;
|
||||
break;
|
||||
case 5:
|
||||
$tiebreak = Tiebreak::BuchholzCut2;
|
||||
break;
|
||||
case 6:
|
||||
$tiebreak = Tiebreak::Sonneborn;
|
||||
break;
|
||||
case 7:
|
||||
$tiebreak = Tiebreak::Cumulative;
|
||||
break;
|
||||
case 8:
|
||||
$tiebreak = Tiebreak::Between;
|
||||
break;
|
||||
case 9:
|
||||
$tiebreak = Tiebreak::Koya;
|
||||
break;
|
||||
case 10:
|
||||
$tiebreak = Tiebreak::Baumbach;
|
||||
break;
|
||||
case 11:
|
||||
$tiebreak = Tiebreak::AveragePerformance;
|
||||
break;
|
||||
case 12:
|
||||
$tiebreak = Tiebreak::Aro;
|
||||
break;
|
||||
case 13:
|
||||
$tiebreak = Tiebreak::AroCut;
|
||||
break;
|
||||
case 14:
|
||||
$tiebreak = Tiebreak::BlackPlayed;
|
||||
break;
|
||||
case 15:
|
||||
$tiebreak = Tiebreak::BlackWin;
|
||||
break;
|
||||
}
|
||||
$tiebreaks[] = new Tiebreak($tiebreak);
|
||||
}
|
||||
$this->getTournament()->setTiebreaks($tiebreaks);
|
||||
|
||||
$this->getTournament()->setBinaryData('[EXCLUSION]', $this->readData('String', $swshandle));
|
||||
$this->getTournament()->setBinaryData('ExclusionType', $this->readData('Int', $swshandle));
|
||||
@ -423,6 +477,7 @@ class Swar4 implements ReaderInterface
|
||||
}
|
||||
fclose($swshandle);
|
||||
$this->getTournament()->pairingsToRounds();
|
||||
$this->addTiebreaks();
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -565,4 +620,24 @@ class Swar4 implements ReaderInterface
|
||||
return DateTime::createFromFormat('Ymd', $string);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
private function addTiebreaks(): Swar4
|
||||
{
|
||||
switch ($this->getTournament()->getSystem()) {
|
||||
case TournamentSystem::American:
|
||||
$firstElement = new Tiebreak(Tiebreak::American);
|
||||
break;
|
||||
case TournamentSystem::Closed:
|
||||
case TournamentSystem::Swiss:
|
||||
default:
|
||||
$firstElement = new Tiebreak(Tiebreak::Points);
|
||||
}
|
||||
$tiebreaks = $this->getTournament()->getTiebreaks();
|
||||
array_unshift($tiebreaks, $firstElement);
|
||||
$this->getTournament()->setTiebreaks($tiebreaks);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -421,6 +421,12 @@ class Tournament
|
||||
case Tiebreak::BuchholzMed:
|
||||
return $this->calculateBuchholz($player, 1, 1);
|
||||
break;
|
||||
case Tiebreak::BuchholzCut2:
|
||||
return $this->calculateBuchholz($player, 2);
|
||||
break;
|
||||
case Tiebreak::BuchholzMed2:
|
||||
return $this->calculateBuchholz($player, 2, 2);
|
||||
break;
|
||||
case Tiebreak::Sonneborn:
|
||||
return $this->calculateSonneborn($player);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user