Skip to content

Commit

Permalink
fix merging grid algo to output correct amount of tries
Browse files Browse the repository at this point in the history
  • Loading branch information
meikpiep committed Oct 26, 2024
1 parent 4b5db25 commit 6614f37
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class MergingCageGridCalculator(
singleCageMerges++
} else {
runsWithoutSuccess++
singleCageTries++
}
}
}
Expand All @@ -76,6 +77,7 @@ class MergingCageGridCalculator(
multiCageMerges++
} else {
runsWithoutSuccess++
multiCageTries++
}
}
}
Expand Down Expand Up @@ -118,15 +120,19 @@ class MergingCageGridCalculator(
val cages = grid.cages

val singleCageAdjacentCounts =
singleCages.map { singleCage ->
grid.cages.count { grid.areAdjacent(singleCage, it) }
}.distinct().sorted()
singleCages
.map { singleCage ->
grid.cages.count { grid.areAdjacent(singleCage, it) }
}.distinct()
.sorted()

val singleCagesOrdered =
singleCageAdjacentCounts.map {
singleCages.filter { singleCage -> grid.cages.count { grid.areAdjacent(singleCage, it) } == it }
.shuffled(randomizer.random())
}.flatten()
singleCageAdjacentCounts
.map {
singleCages
.filter { singleCage -> grid.cages.count { grid.areAdjacent(singleCage, it) } == it }
.shuffled(randomizer.random())
}.flatten()

singleCagesOrdered
.forEach { cage ->
Expand Down Expand Up @@ -160,7 +166,6 @@ class MergingCageGridCalculator(
val (result, duration) =
measureTimedValue {
val newGrid = createNewGridByMergingTwoCages(grid, cage, otherCage, cellsToBeMerged, gridCageType)

return@measureTimedValue Pair(newGrid, MathDokuDLXSolver().solve(newGrid))
}

Expand Down

0 comments on commit 6614f37

Please sign in to comment.