Skip to content

Commit

Permalink
Fixed bug when trying to add single pieces to the biggest group, the …
Browse files Browse the repository at this point in the history
…biggest group object was not the real biggest group object anymore
  • Loading branch information
byWulf committed Aug 21, 2022
1 parent cdeed0e commit 527ed38
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Service/PuzzleSolver/ByWulfSolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,23 +166,23 @@ private function tryToAssignSinglePieces(ByWulfSolverContext $context): void
$this->removeSmallGroupsStrategy->execute($context, $biggestGroup);

// First try to assign all pieces that are still single to the biggest group
if ($this->executeSinglePieceAssignment($context, $biggestGroup, null, null, false, 0)) {
if ($this->executeSinglePieceAssignment($context, null, null, false, 0)) {
return;
}

// Then try to remove all bad connections and do it again
if ($this->executeSinglePieceAssignment($context, $biggestGroup, 0.5, 2, false, 0)) {
if ($this->executeSinglePieceAssignment($context, 0.5, 2, false, 0)) {
return;
}

// Now try to overwrite existing pieces if they fit there better
if ($this->executeSinglePieceAssignment($context, $biggestGroup, null, null, true, 0)) {
if ($this->executeSinglePieceAssignment($context, null, null, true, 0)) {
return;
}

// If there are still pieces missing, do it a few times with a bit of variance
for ($i = 0; $i < 5; ++$i) {
if ($this->executeSinglePieceAssignment($context, $biggestGroup, 0.5, 2, false, 0.2)) {
for ($i = 0; $i < 15; ++$i) {
if ($this->executeSinglePieceAssignment($context, 0.5, 2, false, 0.2)) {
return;
}
}
Expand All @@ -191,12 +191,17 @@ private function tryToAssignSinglePieces(ByWulfSolverContext $context): void
/**
* @
*/
private function executeSinglePieceAssignment(ByWulfSolverContext $context, Group $biggestGroup, ?float $removeMaxProbability, ?int $removeMinimumSidesBelow, bool $canPlaceAboveExistingPlacement, float $variationFactor): bool
private function executeSinglePieceAssignment(ByWulfSolverContext $context, ?float $removeMaxProbability, ?int $removeMinimumSidesBelow, bool $canPlaceAboveExistingPlacement, float $variationFactor): bool
{
if ($removeMaxProbability !== null && $removeMinimumSidesBelow !== null) {
$this->removeBadPiecesStrategy->execute($context, 0.5, 2);
}

$biggestGroup = $context->getSolution()->getBiggestGroup();
if ($biggestGroup === null) {
return true;
}

if ($canPlaceAboveExistingPlacement) {
$this->createMissingGroupsStrategy->execute($context);
$this->fillBlanksWithSinglePiecesStrategy->execute($context, $biggestGroup, true, $variationFactor);
Expand Down

0 comments on commit 527ed38

Please sign in to comment.