Skip to content

Commit

Permalink
fix(validator): update to single
Browse files Browse the repository at this point in the history
  • Loading branch information
thepercival committed May 20, 2024
1 parent c4ed17e commit 00eadf6
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 416 deletions.
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 0 additions & 74 deletions domain/Combinations/MultipleCombinationsCounter.php

This file was deleted.

84 changes: 0 additions & 84 deletions domain/Combinations/MultipleCombinationsCounter/Against.php

This file was deleted.

91 changes: 0 additions & 91 deletions domain/Combinations/MultipleCombinationsCounter/With.php

This file was deleted.

35 changes: 30 additions & 5 deletions domain/Combinations/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@
use SportsHelpers\Against\Side as AgainstSide;
use SportsHelpers\Sport\Variant\Against as AgainstSportVariant;
use SportsPlanning\Combinations\PlaceCombination;
use SportsPlanning\Combinations\PlaceCounterMap;
use SportsPlanning\Game\Against as AgainstGame;
use SportsPlanning\Game\Place\Against as AgainstGamePlace;
use SportsPlanning\Place;
use SportsPlanning\PlaceCounter;
use SportsPlanning\Planning;
use SportsPlanning\Poule;
use SportsPlanning\Sport;

/**
* @template T
*/
abstract class Validator
{
protected AgainstSportVariant $sportVariant;
/**
* @var array<int|string, T>
* @var array<int, PlaceCounterMap>
*/
protected array $counters = [];
protected array $placeCounterMaps = [];

public function __construct(protected Poule $poule, protected Sport $sport)
{
Expand All @@ -32,6 +31,22 @@ public function __construct(protected Poule $poule, protected Sport $sport)
throw new \Exception('only against-sports', E_ERROR);
}
$this->sportVariant = $sportVariant;

$this->initCounters();
}

private function initCounters(): void
{
foreach( $this->poule->getPlaces() as $placeA ) {
$placeCounters = [];
foreach( $this->poule->getPlaces() as $placeB ) {
if( $placeA === $placeB ) {
continue;
}
$placeCounters[$placeB->getPlaceNr()] = new PlaceCounter($placeB);
}
$this->placeCounterMaps[$placeA->getPlaceNr()] = new PlaceCounterMap($placeCounters);
}
}

public function getPlaceCombination(AgainstGame $game, AgainstSide $side): PlaceCombination
Expand All @@ -49,5 +64,15 @@ public function addGames(Planning $planning): void
}
}

public function balanced(): bool
{
foreach ($this->placeCounterMaps as $placeCounterMap) {
if( $placeCounterMap->getAmountDifference() > 0 ) {
return false;
}
}
return true;
}

abstract public function addGame(AgainstGame $game): void;
}
Loading

0 comments on commit 00eadf6

Please sign in to comment.