Merge branch 'task/removing_files' into develop

This commit is contained in:
Jeroen De Meerleer 2020-08-02 21:52:03 +02:00
commit f4c526ff41
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
23 changed files with 692 additions and 579 deletions

View File

@ -15,32 +15,36 @@
<option name="VARIABLE_NAMING_STYLE" value="CAMEL_CASE" />
<option name="BLANK_LINES_BEFORE_RETURN_STATEMENT" value="1" />
<option name="KEEP_RPAREN_AND_LBRACE_ON_ONE_LINE" value="true" />
<option name="SPACES_AROUND_VAR_WITHIN_BRACKETS" value="true" />
<option name="BLANK_LINES_AROUND_CONSTANTS" value="1" />
<option name="KEEP_BLANK_LINES_AFTER_LBRACE" value="1" />
<option name="BLANK_LINES_AFTER_OPENING_TAG" value="1" />
<option name="KEEP_BLANK_LINES_AFTER_LBRACE" value="0" />
<option name="SPACE_BETWEEN_TERNARY_QUEST_AND_COLON" value="true" />
<option name="FORCE_SHORT_DECLARATION_ARRAY_STYLE" value="true" />
<option name="NEW_LINE_AFTER_PHP_OPENING_TAG" value="true" />
<option name="PLACE_PARENS_FOR_CONSTRUCTOR" value="1" />
</PHPCodeStyleSettings>
<codeStyleSettings language="PHP">
<option name="RIGHT_MARGIN" value="120" />
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" />
<option name="BLANK_LINES_AFTER_PACKAGE" value="1" />
<option name="BLANK_LINES_AROUND_FIELD" value="1" />
<option name="ALIGN_MULTILINE_CHAINED_METHODS" value="true" />
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
<option name="ALIGN_MULTILINE_BINARY_OPERATION" value="true" />
<option name="ALIGN_MULTILINE_TERNARY_OPERATION" value="true" />
<option name="ALIGN_MULTILINE_EXTENDS_LIST" value="true" />
<option name="ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION" value="true" />
<option name="SPACE_WITHIN_BRACKETS" value="true" />
<option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACES" value="true" />
<option name="CALL_PARAMETERS_WRAP" value="5" />
<option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
<option name="CALL_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
<option name="METHOD_PARAMETERS_WRAP" value="5" />
<option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
<option name="METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
<option name="EXTENDS_LIST_WRAP" value="5" />
<option name="METHOD_CALL_CHAIN_WRAP" value="5" />
<option name="PARENTHESES_EXPRESSION_LPAREN_WRAP" value="true" />
<option name="PARENTHESES_EXPRESSION_RPAREN_WRAP" value="true" />
@ -49,11 +53,13 @@
<option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" />
<option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
<option name="FOR_STATEMENT_WRAP" value="5" />
<option name="FOR_STATEMENT_LPAREN_ON_NEXT_LINE" value="true" />
<option name="FOR_STATEMENT_RPAREN_ON_NEXT_LINE" value="true" />
<option name="ARRAY_INITIALIZER_WRAP" value="5" />
<option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" />
<option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" />
<option name="ASSIGNMENT_WRAP" value="5" />
<option name="IF_BRACE_FORCE" value="1" />
<option name="IF_BRACE_FORCE" value="3" />
<option name="DOWHILE_BRACE_FORCE" value="3" />
<option name="WHILE_BRACE_FORCE" value="3" />
<option name="FOR_BRACE_FORCE" value="3" />

View File

@ -0,0 +1,17 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PhpCSValidationInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="CODING_STANDARD" value="PSR12" />
<option name="EXTENSIONS" value="php,js,css,inc" />
</inspection_tool>
<inspection_tool class="PhpCompoundNamespaceDepthInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpLongTypeFormInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpMissingVisibilityInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpModifierOrderInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpNewClassMissingParameterListInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpSeparateElseIfInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpTraitsUseListInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpVarUsageInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
</profile>
</component>

12
.php_cs
View File

@ -1,12 +0,0 @@
<?php
$finder = PhpCsFixer\Finder::create()
->exclude(['build', 'vendor'])
->in(__DIR__);
return PhpCsFixer\Config::create()
->setFinder($finder)
->setUsingCache(true)
->setRules([
'@PSR2' => true,
]);

View File

@ -12,6 +12,8 @@ install-dev: ## Installs the required common devtools
@echo "Downloading phpcs"
@wget https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar -O bin/phpcs 2> /dev/null
@wget https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar -O bin/phpcbf 2> /dev/null
@echo "Adding execution rights on the binaries"
@chmod +x bin/phpcs bin/phpcbf bin/phpdoc
@echo "Installation of devtools finished"
@echo "Please add $(shell echo $(PWD))/bin to your PATH"
@ -54,7 +56,7 @@ clean-repo: ## Cleans the git repository
git gc
cs: ## Fixes coding standard problems
vendor/bin/php-cs-fixer fix || true
php bin/phpcs || true
tag: ## Creates a new signed git tag
$(if $(TAG),,$(error TAG is not defined. Pass via "make tag TAG=X.X.X"))

View File

@ -1,4 +1,5 @@
<?php
/**
* Class Constants
*
@ -27,11 +28,28 @@ use JeroenED\Libpairtwo\Enums\Result;
*/
class Constants
{
const Won = [ Result::Won, Result::WonForfait, Result::WonBye, Result::WonAdjourned ];
const Draw = [ Result::Draw, Result::DrawAdjourned ];
const Lost = [ Result::Absent, Result::Bye, Result::Lost, Result::Adjourned ];
const NotPlayed = [ Result::Bye, Result::WonBye, Result::Absent ];
const Played = [ Result::Won, Result::WonForfait, Result::WonBye, Result::WonAdjourned, Result::Draw, Result::DrawAdjourned, Result::Absent, Result::Bye, Result::Lost, Result::Adjourned ];
const Black = [ Color::Black ];
const White = [ Color::White ];
public const WON = [Result::WON, Result::WON_FORFAIT, Result::WON_BYE, Result::WON_ADJOURNED];
public const DRAW = [Result::DRAW, Result::DRAW_ADJOURNED];
public const LOST = [Result::ABSENT, Result::BYE, Result::LOST, Result::ADJOURNED];
public const NOTPLAYED = [Result::BYE, Result::WON_BYE, Result::ABSENT];
public const PLAYED = [
Result::WON,
Result::WON_FORFAIT,
Result::WON_BYE,
Result::WON_ADJOURNED,
Result::DRAW,
Result::DRAW_ADJOURNED,
Result::ABSENT,
Result::BYE,
Result::LOST,
Result::ADJOURNED
];
public const BLACK = [Color::BLACK];
public const WHITE = [Color::WHITE];
}

View File

@ -1,4 +1,5 @@
<?php
/**
* Enum Color
*
@ -26,7 +27,9 @@ use MyCLabs\Enum\Enum;
*/
class Color extends Enum
{
const Black = 'B';
const White = 'W';
const None = '*';
public const BLACK = 'B';
public const NONE = '*';
public const WHITE = 'W';
}

View File

@ -1,4 +1,5 @@
<?php
/**
* Enum Gameresult
*
@ -26,17 +27,29 @@ use MyCLabs\Enum\Enum;
*/
class Gameresult extends Enum
{
const None = '-';
const WhiteWins = '1-0';
const Draw = '0.5-0.5';
const BlackWins = '0-1';
const WhiteWinsForfait = '1-0 FF';
const BlackWinsForfait = '0-1 FF';
const BothLoseForfait = '0-0 FF';
const BothWinAdjourned = '1-1 A';
const WhiteWinsBlackDrawsAdjourned = '1-0.5 A';
const WhiteDrawsBlackWinsAdjourned = '0.5-1 A';
const DrawAdjourned = '0.5-0.5 A';
const WhiteLoseBlackDrawsAdjourned = '0-0.5';
const WhiteDrawsBlackLoseAdjourned = '0.5-0';
public const BLACK_WINS = '0-1';
public const BLACK_WINS_FORFAIT = '0-1 FF';
public const BOTH_LOSE_FORFAIT = '0-0 FF';
public const BOTH_WIN_ADJOURNED = '1-1 A';
public const DRAW = '0.5-0.5';
public const DRAW_ADJOURNED = '0.5-0.5 A';
public const NONE = '-';
public const WHITE_DRAWS_BLACK_LOSE_ADJOURNED = '0.5-0';
public const WHITE_DRAWS_BLACK_WINS_ADJOURNED = '0.5-1 A';
public const WHITE_LOST_BLACK_DRAWS_ADJOURNED = '0-0.5';
public const WHITE_WINS = '1-0';
public const WHITE_WINS_BLACK_DRAWS_ADJOURNED = '1-0.5 A';
public const WHITE_WINS_FORFAIT = '1-0 FF';
}

View File

@ -1,4 +1,5 @@
<?php
/**
* Enum Gender
*
@ -26,7 +27,9 @@ use MyCLabs\Enum\Enum;
*/
class Gender extends Enum
{
const Neutral = 'X'; // Unforturnately, Incompatible with Pairtwo (Dinos)
const Male = 'M';
const Female = 'F';
public const FEMALE = 'F';
public const MALE = 'M';
public const NEUTRAL = 'X'; // Unfortunately, Incompatible with Pairtwo (Dinos)
}

View File

@ -1,4 +1,5 @@
<?php
/**
* Enum Result
*
@ -26,15 +27,25 @@ use MyCLabs\Enum\Enum;
*/
class Result extends Enum
{
const None = '*';
const Lost = '0';
const Draw = '0.5';
const Won = '1';
const Absent = '0 FF';
const WonForfait = '1 FF';
const Adjourned = '0 A';
const DrawAdjourned = '0.5 A';
const WonAdjourned = '1 A';
const Bye = '0 Bye';
const WonBye = '1 Bye';
public const ABSENT = '0 FF';
public const ADJOURNED = '0 A';
public const BYE = '0 Bye';
public const DRAW = '0.5';
public const DRAW_ADJOURNED = '0.5 A';
public const LOST = '0';
public const NONE = '*';
public const WON = '1';
public const WON_ADJOURNED = '1 A';
public const WON_BYE = '1 Bye';
public const WON_FORFAIT = '1 FF';
}

View File

@ -1,4 +1,5 @@
<?php
/**
* Enum Tiebreak
*
@ -26,27 +27,49 @@ use MyCLabs\Enum\Enum;
*/
class Tiebreak extends Enum
{
const None = "";
const Keizer = "Keizer";
const Points = "Points";
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";
const Cumulative = "Cumulative";
const Between = "Mutual Result";
const Koya = "Koya";
const Baumbach = "Most wins"; // Ref: https://en.wikipedia.org/wiki/Tie-breaking_in_Swiss-system_tournaments#Most_wins_(Baumbach) Please tell me why?
const AveragePerformance = "Average performance";
const Performance = "Performance";
const Aro = "Average Rating";
const AroCut = "Average Rating Cut";
const BlackPlayed = "Black played";
const BlackWin = "Black Winned";
const Testmatch = "Testmatch";
const Drawing = "Drawing of lot";
public const ARO = "Average Rating";
public const AROCUT = "Average Rating Cut";
public const AVERAGE_PERFORMANCE = "Average performance";
public const BAUMBACH = "Most wins"; // Ref: https://en.wikipedia.org/wiki/Tie-breaking_in_Swiss-system_tournaments#Most_wins_(Baumbach) Please tell me why?
public const BETWEEN = "Mutual Result";
public const BLACK_PLAYED = "Black played";
public const BLACK_WIN = "Black Winned";
public const BUCHHOLZ = "Buchholz";
public const BUCHHOLZ_CUT = "Buchholz Cut";
public const BUCHHOLZ_CUT_2 = "Buchholz Cut 2";
public const BUCHHOLZ_MED = "Buchholz Median";
public const BUCHHOLZ_MED_2 = "Buchholz Median 2";
public const CUMULATIVE = "Cumulative";
public const DRAWING_OF_LOT = "Drawing of lot";
public const KASHDAN = "Kashdan";
public const KEIZER = "Keizer";
public const KOYA = "Koya";
public const NONE = "";
public const PERFORMANCE = "Performance";
public const POINTS = "Points";
public const SOCCER_KASHDAN = "Soccer Kashdan";
public const SONNEBORN = "Sonneborn-Berger";
public const TESTMATCH = "Testmatch";
}

View File

@ -1,4 +1,5 @@
<?php
/**
* Enum Title
*
@ -26,17 +27,29 @@ use MyCLabs\Enum\Enum;
*/
class Title extends Enum
{
const NONE = '*';
const ELO = 'Elo';
const NM = 'National Master';
const WCM = 'Woman Candidate Master';
const WFM = 'Woman Fide Master';
const CM = 'Candidate Master';
const WIM = 'Woman International Master';
const FM = 'Fide Master';
const WGM = 'Woman Grand Master';
const HM = 'Honorary International Master';
const IM = 'International Master';
const HG = 'Honorary Grand Master';
const GM = 'Grand Master';
public const CM = 'Candidate Master';
public const ELO = 'Elo';
public const FM = 'Fide Master';
public const GM = 'Grand Master';
public const HG = 'Honorary Grand Master';
public const HM = 'Honorary International Master';
public const IM = 'International Master';
public const NM = 'National Master';
public const NONE = '*';
public const WCM = 'Woman Candidate Master';
public const WFM = 'Woman Fide Master';
public const WGM = 'Woman Grand Master';
public const WIM = 'Woman International Master';
}

View File

@ -1,4 +1,5 @@
<?php
/**
* Enum TournamentSystem
*
@ -26,8 +27,11 @@ use MyCLabs\Enum\Enum;
*/
class TournamentSystem extends Enum
{
const Swiss = 'Swiss';
const Closed = 'Closed';
const American = 'American';
const Keizer = 'Keizer';
public const AMERICAN = 'American';
public const CLOSED = 'Closed';
public const KEIZER = 'Keizer';
public const SWISS = 'Swiss';
}

View File

@ -1,4 +1,5 @@
<?php
/**
* Exception IncompatibleReaderException
*

View File

@ -1,4 +1,5 @@
<?php
/**
* Exception LibpairtwoException
*
@ -12,6 +13,8 @@
namespace JeroenED\Libpairtwo\Exceptions;
use Exception;
/**
* Exception LibpairtwoException
*
@ -22,6 +25,6 @@ namespace JeroenED\Libpairtwo\Exceptions;
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
class LibpairtwoException extends \Exception
class LibpairtwoException extends Exception
{
}

View File

@ -1,4 +1,5 @@
<?php
/**
* Class Games
*
@ -36,7 +37,7 @@ class Game
public $White;
/**
* The pairing for this games as seen from blacks's side
* The pairing for this games as seen from black's side
*
* @var Pairing | null
*/
@ -59,6 +60,7 @@ class Game
/**
* Returns fields that were not directly assigned.
* Class Game contains the special field Result containing the result of the game
*
* @param string $key
* @return Gameresult
*/
@ -118,6 +120,6 @@ class Game
return (
$this->White->Player === $game->White->Player &&
$this->Black->Player === $game->Black->Player &&
$this->Result == $game->Result);
$this->Result->getKey() == $game->Result->getKey());
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* Class IOFactory
*
@ -57,8 +58,7 @@ abstract class IOFactory
// create reader class
$readerClass = self::$Readers[$type];
$reader = new $readerClass;
return $reader;
return new $readerClass();
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* Interface ReaderInterface
*
@ -30,7 +31,7 @@ interface ReaderInterface
* Reads out $filename
*
* @param $filename
* @return ReaderInterface
* @return void
*/
public function read(string $filename): void;
}

View File

@ -1,4 +1,5 @@
<?php
/**
* Class Pairing
*
@ -51,6 +52,7 @@ class Pairing
/**
* The result of the Game. Possible values contain Won, Lost, Draw, Forfait, Bye, etc.
*
* @var Result
*/
public $Result;

View File

@ -1,4 +1,5 @@
<?php
/**
* Class Player
*
@ -128,10 +129,14 @@ class Player
*/
public static function PlayersByName(string $search, Tournament $tournament): array
{
/** @var Player[] */
/**
* @var Player[]
*/
$players = $tournament->Players;
/** @var Player[] */
/**
* @var Player[]
*/
$return = [];
foreach ($players as $player) {
@ -145,6 +150,7 @@ class Player
/**
* Returns the elo of elotype for the player
*
* @param string $type
* @return int
*/
@ -203,7 +209,7 @@ class Player
{
$wins = 0;
foreach ($this->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::Won) !== false) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$wins++;
}
}
@ -225,9 +231,9 @@ class Player
$points = 0;
foreach ($this->Pairings as $key => $pairing) {
if ($key < $round || $round == -1) {
if (array_search($pairing->Result, Constants::Won) !== false) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$points = $points + 1;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) {
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$points = $points + 0.5;
}
}
@ -264,11 +270,11 @@ class Player
{
$points = 0;
foreach ($this->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::NotPlayed) !== false) {
if (array_search($pairing->Result, Constants::NOTPLAYED) !== false) {
$points = $points + 0.5;
} elseif (array_search($pairing->Result, Constants::Won) !== false) {
} elseif (array_search($pairing->Result, Constants::WON) !== false) {
$points = $points + 1;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) {
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$points = $points + 0.5;
}
}
@ -281,21 +287,21 @@ class Player
*
* @param $type
* @param $unratedElo
* @return int
* @return float
*/
public function Performance(string $type, int $unratedElo): float
{
$total = 0;
$opponents = 0;
foreach ($this->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::NotPlayed) === false) {
if (array_search($pairing->Result, Constants::NOTPLAYED) === false) {
$opponentElo = $pairing->Opponent->getElo($type);
$opponentElo = $opponentElo != 0 ? $opponentElo : $unratedElo;
if (array_search($pairing->Result, Constants::Won) !== false) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$total += $opponentElo + 400;
} elseif (array_search($pairing->Result, Constants::Lost) !== false) {
} elseif (array_search($pairing->Result, Constants::LOST) !== false) {
$total += $opponentElo - 400;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) {
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$total += $opponentElo;
}
$opponents++;
@ -314,7 +320,7 @@ class Player
{
$total = 0;
foreach ($this->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::Played) !== false) {
if (array_search($pairing->Result, Constants::PLAYED) !== false) {
$total++;
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* Reader Pairtwo6
*
@ -10,9 +11,9 @@
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo\Readers;
use InvalidArgumentException;
use JeroenED\Libpairtwo\Enums\Color;
use JeroenED\Libpairtwo\Enums\Gender;
use JeroenED\Libpairtwo\Enums\Result;
@ -39,11 +40,15 @@ use DateTime;
*/
class Pairtwo6 implements ReaderInterface
{
const PT_DAYFACTOR = 32;
const PT_MONTHFACTOR = 16;
const PT_YEARFACTOR = 512;
const PT_PASTOFFSET = 117;
const CompatibleVersions = ['6.', '5.'];
public const PT_DAYFACTOR = 32;
public const PT_MONTHFACTOR = 16;
public const PT_YEARFACTOR = 512;
public const PT_PASTOFFSET = 117;
public const COMPATIBLE_VERSIONS = ['6.', '5.'];
/**
* Version of Pairtwo this file was created with
@ -61,6 +66,7 @@ class Pairtwo6 implements ReaderInterface
/**
* Binary data that was read out of the pairing file
*
* @var bool|DateTime|int|string[]
*/
private $BinaryData;
@ -109,7 +115,7 @@ class Pairtwo6 implements ReaderInterface
$this->Release = $this->readData('String', substr($swscontents, $offset, $length));
$offset += $length;
if (array_search(substr($this->Release, 0, 2), self::CompatibleVersions) === false) {
if (array_search(substr($this->Release, 0, 2), self::COMPATIBLE_VERSIONS) === false) {
throw new IncompatibleReaderException("This file was not created with Pairtwo 5 or higher");
}
@ -261,53 +267,53 @@ class Pairtwo6 implements ReaderInterface
$length = 4;
switch ($this->readData('Int', substr($swscontents, $offset, $length))) {
case 1:
$tiebreak = Tiebreak::Buchholz;
$tiebreak = Tiebreak::BUCHHOLZ;
break;
case 2:
$tiebreak = Tiebreak::BuchholzMed;
$tiebreak = Tiebreak::BUCHHOLZ_MED;
break;
case 3:
$tiebreak = Tiebreak::BuchholzCut;
$tiebreak = Tiebreak::BUCHHOLZ_CUT;
break;
case 4:
$tiebreak = Tiebreak::Sonneborn;
$tiebreak = Tiebreak::SONNEBORN;
break;
case 5:
$tiebreak = Tiebreak::Kashdan;
$tiebreak = Tiebreak::KASHDAN;
break;
case 6:
$tiebreak = Tiebreak::Cumulative;
$tiebreak = Tiebreak::CUMULATIVE;
break;
case 7:
$tiebreak = Tiebreak::Between;
$tiebreak = Tiebreak::BETWEEN;
break;
case 8:
$tiebreak = Tiebreak::Koya;
$tiebreak = Tiebreak::KOYA;
break;
case 9:
$tiebreak = Tiebreak::Baumbach;
$tiebreak = Tiebreak::BAUMBACH;
break;
case 10:
$tiebreak = Tiebreak::Performance;
$tiebreak = Tiebreak::PERFORMANCE;
break;
case 11:
$tiebreak = Tiebreak::Aro;
$tiebreak = Tiebreak::ARO;
break;
case 12:
$tiebreak = Tiebreak::AroCut;
$tiebreak = Tiebreak::AROCUT;
break;
case 13:
$tiebreak = Tiebreak::BlackPlayed;
$tiebreak = Tiebreak::BLACK_PLAYED;
break;
case 14:
$tiebreak = Tiebreak::Testmatch;
$tiebreak = Tiebreak::TESTMATCH;
break;
case 15:
$tiebreak = Tiebreak::Drawing;
$tiebreak = Tiebreak::DRAWING_OF_LOT;
break;
case 0:
default:
$tiebreak = Tiebreak::None;
$tiebreak = Tiebreak::NONE;
break;
}
$this->Tournament->addTieBreak(new Tiebreak($tiebreak));
@ -447,13 +453,13 @@ class Pairtwo6 implements ReaderInterface
$length = 1;
switch ($this->readData('Int', substr($swscontents, $offset, $length))) {
case 1:
$gender = Gender::Male;
$gender = Gender::MALE;
break;
case 2:
$gender = Gender::Female;
$gender = Gender::FEMALE;
break;
default:
$gender = Gender::Neutral;
$gender = Gender::NEUTRAL;
break;
}
$player->Gender = new Gender($gender);
@ -498,12 +504,12 @@ class Pairtwo6 implements ReaderInterface
$this->Tournament->addPlayer($player);
}
// PlayerNames
$length = (Integer)$this->NewNamePos + 0;
$length = (int)$this->NewNamePos + 0;
$this->PlayerNames = substr($swscontents, $offset, $length);
$offset += $length;
for ($i = 0; $i < $this->NewPlayer; $i++) {
$player = $this->Tournament->PlayerById($i);
$player = $this->Tournament->playerById($i);
$namelength = $player->NameLength;
$nameoffset = $player->NamePos;
$player->Name = $this->readData("String", substr($this->PlayerNames, $nameoffset, $namelength));
@ -585,17 +591,17 @@ class Pairtwo6 implements ReaderInterface
$length = 4;
switch ($this->readData('Int', substr($swscontents, $offset, $length))) {
case 2:
$system = TournamentSystem::Closed;
$system = TournamentSystem::CLOSED;
break;
case 4:
$system = TournamentSystem::American;
$system = TournamentSystem::AMERICAN;
break;
case 6:
$system = TournamentSystem::Keizer;
$system = TournamentSystem::KEIZER;
break;
case 0:
default:
$system = TournamentSystem::Swiss;
$system = TournamentSystem::SWISS;
break;
}
$this->Tournament->System = new TournamentSystem($system);
@ -651,12 +657,12 @@ class Pairtwo6 implements ReaderInterface
for ($x = 0; $x < $this->CreatedRounds; $x++) {
$pairing = new Pairing();
$pairing->Player = $this->Tournament->PlayerById($i);
$pairing->Player = $this->Tournament->playerById($i);
$length = 4;
$opponent = $this->readData('Int', substr($swscontents, $offset, $length));
if ($opponent != 4294967295) {
$pairing->Opponent = $this->Tournament->PlayerById($opponent);
$pairing->Opponent = $this->Tournament->playerById($opponent);
}
$offset += $length;
@ -665,15 +671,15 @@ class Pairtwo6 implements ReaderInterface
switch ($this->readData('Int', substr($swscontents, $offset, $length))) {
case 255:
case 253:
$color = Color::Black;
$color = Color::BLACK;
break;
case 1:
case 3:
$color = Color::White;
$color = Color::WHITE;
break;
case 0:
default:
$color = Color::None;
$color = Color::NONE;
break;
}
$pairing->Color = new Color($color);
@ -682,38 +688,38 @@ class Pairtwo6 implements ReaderInterface
$length = 1;
switch ($this->readData('Int', substr($swscontents, $offset, $length))) {
case 1:
$result = Result::Lost;
$result = Result::LOST;
break;
case 2:
$result = Result::Absent;
$result = Result::ABSENT;
break;
case 3:
$result = Result::Adjourned;
$result = Result::ADJOURNED;
break;
case 4:
$result = Result::Bye;
$result = Result::BYE;
break;
case 6:
$result = Result::Draw;
$result = Result::DRAW;
break;
case 8:
$result = Result::DrawAdjourned;
$result = Result::DRAW_ADJOURNED;
break;
case 11:
$result = Result::Won;
$result = Result::WON;
break;
case 12:
$result = Result::WonForfait;
$result = Result::WON_FORFAIT;
break;
case 13:
$result = Result::WonAdjourned;
$result = Result::WON_ADJOURNED;
break;
case 14:
$result = Result::WonBye;
$result = Result::WON_BYE;
break;
case 0:
default:
$result = Result::None;
$result = Result::NONE;
break;
}
$pairing->Result = new Result($result);
@ -759,7 +765,6 @@ class Pairtwo6 implements ReaderInterface
return (is_null($default)) ? '' : $default;
}
return iconv('windows-1252', 'utf-8', $data);
break;
case 'Hex':
case 'Int':
case 'Bool':
@ -793,12 +798,11 @@ class Pairtwo6 implements ReaderInterface
}
return $this->convertUIntToTimestamp(hexdec($hex));
} elseif ($type == 'Bool') {
return ($hex == "01") ? true : false;
return ($hex == "01");
}
break;
default:
throw new \InvalidArgumentException("Datatype not known");
break;
throw new InvalidArgumentException("Datatype not known");
}
return false;
@ -844,13 +848,13 @@ class Pairtwo6 implements ReaderInterface
private function addTiebreaks(): void
{
switch ($this->Tournament->System) {
case TournamentSystem::Keizer:
$firstElement = new Tiebreak(Tiebreak::Keizer);
case TournamentSystem::KEIZER:
$firstElement = new Tiebreak(Tiebreak::KEIZER);
break;
case TournamentSystem::American:
case TournamentSystem::Closed:
case TournamentSystem::Swiss:
$firstElement = new Tiebreak(Tiebreak::Points);
case TournamentSystem::AMERICAN:
case TournamentSystem::CLOSED:
case TournamentSystem::SWISS:
$firstElement = new Tiebreak(Tiebreak::POINTS);
break;
}
$tiebreaks = $this->Tournament->Tiebreaks;

View File

@ -1,4 +1,5 @@
<?php
/**
* Reader Swar-4
*
@ -9,8 +10,10 @@
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo\Readers;
use InvalidArgumentException;
use JeroenED\Libpairtwo\Enums\Color;
use JeroenED\Libpairtwo\Enums\Gender;
use JeroenED\Libpairtwo\Enums\Result;
@ -58,10 +61,12 @@ class Swar4 implements ReaderInterface
*/
private $BinaryData;
/** @var array */
const CompatibleVersions = ['v4.'];
/**
* @var array
*/
public const COMPATIBLE_VERSIONS = ['v4.'];
const Tempos = [
public const TEMPOS = [
[
'105 min/40 moves + 15 min. QPF',
'120 min/40 moves + 15 min. with incr. 30" starting from 40th move',
@ -78,7 +83,8 @@ class Swar4 implements ReaderInterface
'90 min with incr. 30"',
'50 min with incr. 10"',
'other'
],[
],
[
'10 min. with incr. 10"',
'10 min. with incr. 15"',
'10 min. with incr.5"',
@ -102,7 +108,8 @@ class Swar4 implements ReaderInterface
'45 min. QPF',
'8 min. with incr.4"',
'other'
],[
],
[
'3 min. with incr. 2"',
'3 min. with incr. 3"',
'4 min. with incr. 2"',
@ -124,6 +131,7 @@ class Swar4 implements ReaderInterface
* Actually reads the Swar-File
*
* @param string $filename
*
* @throws IncompatibleReaderException
*/
public function read(string $filename): void
@ -131,7 +139,7 @@ class Swar4 implements ReaderInterface
$swshandle = fopen($filename, 'rb');
$this->Release = $this->readData('String', $swshandle);
if (array_search(substr($this->Release, 0, 3), self::CompatibleVersions) === false) {
if (array_search(substr($this->Release, 0, 3), self::COMPATIBLE_VERSIONS) === false) {
throw new IncompatibleReaderException("This file was not created with Swar 4");
}
@ -181,16 +189,16 @@ class Swar4 implements ReaderInterface
case 3:
case 4:
default:
$system = TournamentSystem::Swiss;
$system = TournamentSystem::SWISS;
break;
case 5:
case 6:
case 7:
$system = TournamentSystem::Closed;
$system = TournamentSystem::CLOSED;
break;
case 8:
case 9:
$system = TournamentSystem::American;
$system = TournamentSystem::AMERICAN;
break;
}
$this->Tournament->System = new TournamentSystem($system);
@ -244,7 +252,7 @@ class Swar4 implements ReaderInterface
// [DATES]
$this->readData('String', $swshandle);
$this->Tournament->Tempo = Self::Tempos[$this->Tournament->TournoiStd][$this->Tournament->TempoIndex];
$this->Tournament->Tempo = self::TEMPOS[ $this->Tournament->TournoiStd ][ $this->Tournament->TempoIndex ];
for ($i = 0; $i < $this->Tournament->NoOfRounds; $i++) {
$round = new Round();
@ -261,52 +269,52 @@ class Swar4 implements ReaderInterface
switch ($this->readData('Int', $swshandle)) {
case 0:
default:
$tiebreak = Tiebreak::None;
$tiebreak = Tiebreak::NONE;
break;
case 1:
$tiebreak = Tiebreak::Buchholz;
$tiebreak = Tiebreak::BUCHHOLZ;
break;
case 2:
$tiebreak = Tiebreak::BuchholzMed;
$tiebreak = Tiebreak::BUCHHOLZ_MED;
break;
case 3:
$tiebreak = Tiebreak::BuchholzMed2;
$tiebreak = Tiebreak::BUCHHOLZ_MED_2;
break;
case 4:
$tiebreak = Tiebreak::BuchholzCut;
$tiebreak = Tiebreak::BUCHHOLZ_CUT;
break;
case 5:
$tiebreak = Tiebreak::BuchholzCut2;
$tiebreak = Tiebreak::BUCHHOLZ_CUT_2;
break;
case 6:
$tiebreak = Tiebreak::Sonneborn;
$tiebreak = Tiebreak::SONNEBORN;
break;
case 7:
$tiebreak = Tiebreak::Cumulative;
$tiebreak = Tiebreak::CUMULATIVE;
break;
case 8:
$tiebreak = Tiebreak::Between;
$tiebreak = Tiebreak::BETWEEN;
break;
case 9:
$tiebreak = Tiebreak::Koya;
$tiebreak = Tiebreak::KOYA;
break;
case 10:
$tiebreak = Tiebreak::Baumbach;
$tiebreak = Tiebreak::BAUMBACH;
break;
case 11:
$tiebreak = Tiebreak::AveragePerformance;
$tiebreak = Tiebreak::AVERAGE_PERFORMANCE;
break;
case 12:
$tiebreak = Tiebreak::Aro;
$tiebreak = Tiebreak::ARO;
break;
case 13:
$tiebreak = Tiebreak::AroCut;
$tiebreak = Tiebreak::AROCUT;
break;
case 14:
$tiebreak = Tiebreak::BlackPlayed;
$tiebreak = Tiebreak::BLACK_PLAYED;
break;
case 15:
$tiebreak = Tiebreak::BlackWin;
$tiebreak = Tiebreak::BLACK_WIN;
break;
}
$tiebreaks[] = new Tiebreak($tiebreak);
@ -357,13 +365,13 @@ class Swar4 implements ReaderInterface
$player->DateOfBirth = $this->readData('Date', $swshandle);
switch ($this->readData('Int', $swshandle)) {
case 1:
$gender = Gender::Male;
$gender = Gender::MALE;
break;
case 2:
$gender = Gender::Female;
$gender = Gender::FEMALE;
break;
default:
$gender = Gender::Neutral;
$gender = Gender::NEUTRAL;
break;
}
$player->Gender = new Gender($gender);
@ -453,53 +461,54 @@ class Swar4 implements ReaderInterface
while (isset($this->Tournament->Pairing[ $ptn ][ 'round' ])) {
$pairing = new Pairing();
$pairing->Player = $this->Tournament->PlayerById($this->Tournament->Pairing[$ptn]['player']);
$pairing->Player = $this->Tournament->playerById($this->Tournament->Pairing[ $ptn ][ 'player' ]);
$pairing->Round = $this->Tournament->Pairing[ $ptn ][ 'round' ];
if ($this->Tournament->Pairing[ $ptn ][ 'opponent' ] != 4294967295) {
$pairing->Opponent = $this->Tournament->PlayerById($inscriptionNos[$this->Tournament->Pairing[$ptn]['opponent']]);
$pairing->Opponent =
$this->Tournament->playerById($inscriptionNos[ $this->Tournament->Pairing[ $ptn ][ 'opponent' ] ]);
}
switch ($this->Tournament->Pairing[ $ptn ][ 'result' ]) {
case '1000':
$result = Result::Lost;
$result = Result::LOST;
break;
case '01':
$result = Result::Absent;
$result = Result::ABSENT;
break;
case '0010':
$result = Result::Bye;
$result = Result::BYE;
break;
case '2000':
$result = Result::Draw;
$result = Result::DRAW;
break;
case '4000':
$result = Result::Won;
$result = Result::WON;
break;
case '04':
$result = Result::WonForfait;
$result = Result::WON_FORFAIT;
break;
case '40':
$result = Result::WonBye;
$result = Result::WON_BYE;
break;
case '00':
default:
$result = Result::None;
$result = Result::NONE;
break;
}
if (array_search($this->Tournament->Pairing[ $ptn ][ 'table' ], [16383, 8191]) !== false) {
$result = Result::Absent;
$result = Result::ABSENT;
}
$pairing->Result = new Result($result);
switch ($this->Tournament->Pairing[ $ptn ][ 'color' ]) {
case 4294967295:
$color = Color::Black;
$color = Color::BLACK;
break;
case 1:
$color = Color::White;
$color = Color::WHITE;
break;
case 0:
default:
$color = Color::None;
$color = Color::NONE;
break;
}
$pairing->Color = new Color($color);
@ -526,6 +535,7 @@ class Swar4 implements ReaderInterface
* @param string $type
* @param $handle
* @param null $default
*
* @return array|bool|DateTime|false|float|int|string|null
*/
private function readData(string $type, $handle, $default = null)
@ -542,11 +552,13 @@ class Swar4 implements ReaderInterface
if ($data == '') {
return (is_null($default)) ? '' : $default;
}
return iconv('windows-1252', 'utf-8', $data);
} elseif ($type == 'Date') {
if ($data == '') {
return (is_null($default)) ? $this->convertStringToDate('01/01/1900') : $default;
}
return $this->convertStringToDate($data);
}
break;
@ -571,19 +583,20 @@ class Swar4 implements ReaderInterface
if ($hex == '00') {
return (is_null($default)) ? '00' : $default;
}
return $hex;
} elseif ($type == 'Int') {
if ($hex == '00') {
return (is_null($default)) ? 0 : $default;
}
return hexdec($hex);
} elseif ($type == 'Bool') {
return ($hex == "01") ? true : false;
return ($hex == "01");
}
break;
default:
throw new \InvalidArgumentException("Datatype not known");
break;
throw new InvalidArgumentException("Datatype not known");
}
return false;
@ -593,6 +606,7 @@ class Swar4 implements ReaderInterface
* Returns binary data that was read out the swar file but was not needed immediately
*
* @param string $key
*
* @return bool|DateTime|int|string|null
*/
public function __get(string $key)
@ -600,6 +614,7 @@ class Swar4 implements ReaderInterface
if (isset($this->BinaryData[ $key ])) {
return $this->BinaryData[ $key ];
}
return null;
}
@ -616,7 +631,9 @@ class Swar4 implements ReaderInterface
/**
* Converts a swar-4 string to a \DateTime object
*
* @param string $string
*
* @return DateTime
*/
public function convertStringToDate(string $string): DateTime
@ -625,6 +642,10 @@ class Swar4 implements ReaderInterface
return DateTime::createFromFormat('d/m/Y', $string);
} elseif (strlen($string) == 8) {
return DateTime::createFromFormat('Ymd', $string);
} else {
$default = new DateTime();
$default->setTimestamp(0);
return $default;
}
}
@ -634,11 +655,11 @@ class Swar4 implements ReaderInterface
private function addTiebreaks(): void
{
switch ($this->Tournament->System) {
case TournamentSystem::American:
case TournamentSystem::Closed:
case TournamentSystem::Swiss:
case TournamentSystem::AMERICAN:
case TournamentSystem::CLOSED:
case TournamentSystem::SWISS:
default:
$firstElement = new Tiebreak(Tiebreak::Points);
$firstElement = new Tiebreak(Tiebreak::POINTS);
}
$tiebreaks = $this->Tournament->Tiebreaks;
array_unshift($tiebreaks, $firstElement);

View File

@ -1,4 +1,5 @@
<?php
/**
* Class Round
*
@ -89,7 +90,7 @@ class Round
$allPairings = $this->Pairings;
$byePairings = [];
foreach ($allPairings as $pairing) {
if ($pairing->Result == Result::WonBye) {
if ($pairing->Result == Result::WON_BYE) {
$byePairings[] = $pairing;
}
}
@ -106,7 +107,7 @@ class Round
$allPairings = $this->Pairings;
$absentPairings = [];
foreach ($allPairings as $pairing) {
if ($pairing->Result == Result::Absent) {
if ($pairing->Result == Result::ABSENT) {
$absentPairings[] = $pairing;
}
}

View File

@ -1,4 +1,5 @@
<?php
/**
* The file contains the Tournament class which takes care of almost every element in your tournament
*
@ -38,7 +39,6 @@ class Tournament
/**
* Organiser of the tournament (eg. Donald J. Trump)
*
*
* @var string
*/
public $Organiser;
@ -80,6 +80,7 @@ class Tournament
/**
* Start date (First round or Players meeting) of the tournament
*
* @var DateTime
*/
public $StartDate;
@ -114,6 +115,7 @@ class Tournament
/**
* The tempo of the tournament (eg. 90 min/40 moves + 30 sec. increment starting from move 1)
*
* @var string
*/
public $Tempo;
@ -205,10 +207,10 @@ class Tournament
/**
* Gets a player by its ID
*
* @param integer $id
* @param int $id
* @return Player
*/
public function PlayerById(int $id): Player
public function playerById(int $id): Player
{
return $this->Players[$id];
}
@ -217,7 +219,6 @@ class Tournament
* Adds a player
*
* @param Player $Player
*
*/
public function addPlayer(Player $Player): void
{
@ -231,7 +232,6 @@ class Tournament
*
* @param int $id
* @param Player $player
*
*/
public function updatePlayer(int $id, Player $player): void
{
@ -244,7 +244,6 @@ class Tournament
* Adds a Tiebreak
*
* @param Tiebreak $tiebreak
*
*/
public function addTiebreak(Tiebreak $tiebreak): void
{
@ -257,7 +256,6 @@ class Tournament
* Adds a round with given Round object
*
* @param Round $round
*
*/
public function addRound(Round $round): void
{
@ -272,7 +270,7 @@ class Tournament
* @param int $roundNo
* @return Round
*/
public function RoundByNo(int $roundNo): Round
public function roundByNo(int $roundNo): Round
{
return $this->Rounds[$roundNo];
}
@ -281,7 +279,6 @@ class Tournament
* Adds a pairing to the tournament
*
* @param Pairing $pairing
*
*/
public function addPairing(Pairing $pairing): void
{
@ -295,7 +292,6 @@ class Tournament
* Adds an arbiter to the tournament
*
* @param string $Arbiter
*
*/
public function addArbiter(string $Arbiter): void
{
@ -306,28 +302,23 @@ class Tournament
/**
* Converts pairings into games with a black and white player
*
*
*/
public function pairingsToRounds(): void
{
/** @var Pairing[] $pairings */
$pairings = $this->Pairings;
/** @var Pairing[] */
/**
* @var Pairing[]
*/
$cache = array();
/** @var int[] */
$lastboards;
/** @var Pairing $pairing */
foreach ($pairings as $pairing) {
// Add pairing to player
$pairing->Player->addPairing($pairing);
$round = $pairing->Round;
$color = $pairing->Color;
$this->RoundByNo($round)->addPairing($pairing);
$this->roundByNo($round)->addPairing($pairing);
$opponent = null;
/**
@ -344,19 +335,17 @@ class Tournament
}
}
$game = new Game();
if ($color->getValue() == Color::White) {
if ($color->getValue() == Color::WHITE) {
$game->White = $pairing;
$game->Black = $opponent;
} elseif ($color->getValue() == Color::Black) {
} elseif ($color->getValue() == Color::BLACK) {
$game->White = $opponent;
$game->Black = $pairing;
}
if (is_null($game->White) || is_null($game->Black)) {
$cache[] = $pairing;
} else {
// Check if game already exists
if (!$this->gameExists($game, $round)) {
} elseif (!$this->gameExists($game, $round)) { // Check if game already exists
$game->Board = $game->White->Board;
// Add board if inexistent
if ($game->Board == -1) {
@ -373,7 +362,6 @@ class Tournament
}
}
}
}
/**
* Checks if a game already is already registered
@ -415,7 +403,6 @@ class Tournament
*
* @param Game $game
* @param int $round
*
*/
public function addGame(Game $game, int $round): void
{
@ -425,7 +412,7 @@ class Tournament
$this->addRound($roundObj);
}
$this->RoundByNo($round)->addGame($game);
$this->roundByNo($round)->addGame($game);
}
/**
@ -503,66 +490,46 @@ class Tournament
private function calculateTiebreak(Tiebreak $tiebreak, Player $player, int $tbkey = 0): float
{
switch ($tiebreak) {
case Tiebreak::Keizer:
case Tiebreak::KEIZER:
return $this->calculateKeizer($player);
break;
case Tiebreak::Points:
case Tiebreak::POINTS:
return $this->calculatePoints($player);
break;
case Tiebreak::Baumbach:
case Tiebreak::BAUMBACH:
return $this->calculateBaumbach($player);
break;
case Tiebreak::BlackPlayed:
case Tiebreak::BLACK_PLAYED:
return $this->calculateBlackPlayed($player);
break;
case Tiebreak::BlackWin:
case Tiebreak::BLACK_WIN:
return $this->calculateBlackWin($player);
break;
case Tiebreak::Between:
case Tiebreak::BETWEEN:
return $this->calculateMutualResult($player, $this->Players, $tbkey);
break;
case Tiebreak::Aro:
case Tiebreak::ARO:
return $this->calculateAverageRating($player, $this->PriorityElo);
break;
case Tiebreak::AroCut:
case Tiebreak::AROCUT:
return $this->calculateAverageRating($player, $this->PriorityElo, 1);
break;
case Tiebreak::Koya:
case Tiebreak::KOYA:
return $this->calculateKoya($player);
break;
case Tiebreak::Buchholz:
case Tiebreak::BUCHHOLZ:
return $this->calculateBuchholz($player);
break;
case Tiebreak::BuchholzCut:
case Tiebreak::BUCHHOLZ_CUT:
return $this->calculateBuchholz($player, 1);
break;
case Tiebreak::BuchholzMed:
case Tiebreak::BUCHHOLZ_MED:
return $this->calculateBuchholz($player, 1, 1);
break;
case Tiebreak::BuchholzCut2:
case Tiebreak::BUCHHOLZ_CUT_2:
return $this->calculateBuchholz($player, 2);
break;
case Tiebreak::BuchholzMed2:
case Tiebreak::BUCHHOLZ_MED_2:
return $this->calculateBuchholz($player, 2, 2);
break;
case Tiebreak::Sonneborn:
case Tiebreak::SONNEBORN:
return $this->calculateSonneborn($player);
break;
case Tiebreak::Kashdan:
case Tiebreak::KASHDAN:
return $this->calculateKashdan($player, ["Won" => 4, "Draw" => 2, "Lost" => 1, "NotPlayed" => 0]);
break;
case Tiebreak::SoccerKashdan:
case Tiebreak::SOCCER_KASHDAN:
return $this->calculateKashdan($player, ["Won" => 3, "Draw" => 1, "Lost" => 0, "NotPlayed" => -1]);
break;
case Tiebreak::Cumulative:
case Tiebreak::CUMULATIVE:
return $this->calculateCumulative($player);
break;
case Tiebreak::AveragePerformance:
case Tiebreak::AVERAGE_PERFORMANCE:
return $this->calculateAveragePerformance($player, $this->PriorityElo);
break;
case Tiebreak::Performance:
case Tiebreak::PERFORMANCE:
return $player->Performance($this->PriorityElo, $this->NonRatedElo);
break;
default:
return 0;
}
@ -632,8 +599,8 @@ class Tournament
{
$totalwins = 0;
foreach ($player->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::NotPlayed) === false) {
if (array_search($pairing->Result, Constants::Won) !== false) {
if (array_search($pairing->Result, Constants::NOTPLAYED) === false) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$totalwins++;
}
}
@ -652,7 +619,7 @@ class Tournament
{
$totalwins = 0;
foreach ($player->Pairings as $pairing) {
if (array_search($pairing->Color, Constants::Black) !== false) {
if (array_search($pairing->Color, Constants::BLACK) !== false) {
$totalwins++;
}
}
@ -669,7 +636,7 @@ class Tournament
{
$totalwins = 0;
foreach ($player->Pairings as $pairing) {
if (array_search($pairing->Color, Constants::Black) !== false && array_search($pairing->Result, Constants::Won) !== false) {
if (array_search($pairing->Color, Constants::BLACK) !== false && array_search($pairing->Result, Constants::WON) !== false) {
$totalwins++;
}
}
@ -713,9 +680,9 @@ class Tournament
$totalmatches = 0;
foreach ($player->Pairings as $pairing) {
if (array_search($pairing->Opponent, $interestingplayers) !== false) {
if (array_search($pairing->Result, Constants::Won) !== false) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$points = $points + 1;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) {
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$points = $points + 0.5;
}
$totalmatches++;
@ -741,7 +708,7 @@ class Tournament
$pairings = $player->Pairings;
$allratings = [];
foreach ($pairings as $pairing) {
if (array_search($pairing->Result, Constants::NotPlayed) === false) {
if (array_search($pairing->Result, Constants::NOTPLAYED) === false) {
$toadd = $pairing->Opponent->getElo($type);
if ($toadd != 0) {
$allratings[] = $toadd;
@ -771,7 +738,7 @@ class Tournament
$pairings = $player->Pairings;
$allratings = [];
foreach ($pairings as $pairing) {
if (array_search($pairing->Result, Constants::NotPlayed) === false) {
if (array_search($pairing->Result, Constants::NOTPLAYED) === false) {
$toadd = $pairing->Opponent->Performance($type, $this->NonRatedElo);
if ($toadd != 0) {
$allratings[] = $toadd;
@ -796,9 +763,9 @@ class Tournament
$tiebreak = 0;
foreach ($player->Pairings as $plkey => $plpairing) {
if (($plpairing->Opponent->calculatePoints() / count($plpairing->Opponent->Pairings) * 100) >= $cut) {
if (array_search($plpairing->Result, Constants::Won) !== false) {
if (array_search($plpairing->Result, Constants::WON) !== false) {
$tiebreak += 1;
} elseif (array_search($plpairing->Result, Constants::Draw) !== false) {
} elseif (array_search($plpairing->Result, Constants::DRAW) !== false) {
$tiebreak += 0.5;
}
}
@ -809,6 +776,7 @@ class Tournament
/**
* The combined points of the opponents
*
* @param Player $player
* @param int $cutlowest
* @param int $cuthighest
@ -828,21 +796,24 @@ class Tournament
$intpairings[] = $player->calculatePointsForVirtualPlayer($key);
} else {
$intpairings[] = $pairing->Opponent->calculatePointsForTiebreaks();
if (array_search($pairing->Result, Constants::Won) !== false) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$curpoints += 1;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) {
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$curpoints += 0.5;
}
}
$curround++;
}
usort($intpairings, function ($a, $b) {
usort(
$intpairings,
function ($a, $b) {
if ($b == $a) {
return 0;
}
return ($a > $b) ? 1 : -1;
});
}
);
$intpairings = array_slice($intpairings, $cutlowest);
$intpairings = array_slice($intpairings, 0 - $cuthighest);
@ -862,13 +833,13 @@ class Tournament
$tiebreak = 0;
foreach ($player->Pairings as $key => $pairing) {
if ($pairing->Opponent) {
if (array_search($pairing->Result, Constants::Won) !== false) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$tiebreak += $pairing->Opponent->calculatePointsForTiebreaks();
} elseif (array_search($pairing->Result, Constants::Draw) !== false) {
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$tiebreak += $pairing->Opponent->calculatePointsForTiebreaks() / 2;
}
}
if (array_search($pairing->Result, Constants::NotPlayed) !== false) {
if (array_search($pairing->Result, Constants::NOTPLAYED) !== false) {
$tiebreak += $player->calculatePointsForVirtualPlayer($key);
}
}
@ -888,15 +859,15 @@ class Tournament
$tiebreak = 0;
foreach ($player->Pairings as $pairing) {
$toadd = 0;
if (array_search($pairing->Result, Constants::Won) !== false) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$toadd = $points["Won"];
} elseif (array_search($pairing->Result, Constants::Draw) !== false) {
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$toadd = $points["Draw"];
} elseif (array_search($pairing->Result, Constants::Lost) !== false) {
} elseif (array_search($pairing->Result, Constants::LOST) !== false) {
$toadd = $points["Lost"];
}
if (array_search($pairing->Result, Constants::NotPlayed) !== false) {
if (array_search($pairing->Result, Constants::NOTPLAYED) !== false) {
$toadd = $points["NotPlayed"];
}
$tiebreak += $toadd;
@ -916,9 +887,9 @@ class Tournament
$score = [];
foreach ($player->Pairings as $pairing) {
$toadd = 0;
if (array_search($pairing->Result, Constants::Won) !== false) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$toadd = 1;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) {
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$toadd = 0.5;
}
$tiebreak += $toadd;