- commit
- 853e2a35e3b4c926075cc42ed1e08d32fdd6d46c
- parent
- 8f423c4febadb26efb177d69c6da6d2c924ae945
- author
- Dami <dami.etoile@gmail.com>
| M | games/ | 16 | +++++++++++++++- |
| M | games/ | 3 | +++ |
@@ -58,6 +58,12 @@ func generatePuzzleSeededWithProfile(width, height, maxCage int, givenRatio floa
5858 if countSolutions(geo, givens, 2) != 1 {5959 continue6060 }61+ if hasOversizeCage(cages, maxCage) {62+ continue63+ }64+ if profile.maxSingletonCages >= 0 && countSingletonCages(cages) > profile.maxSingletonCages {65+ continue66+ }6167 6268 return Puzzle{6369 Width: width,@@ -126,7 +132,6 @@ func normalizeSingletonCages(width, height, maxCage int, cages []Cage, profile g
126132 if len(singletons) == 0 {127133 break128134 }129-130135 singletonIdx := singletons[rng.IntN(len(singletons))]131136 targetIdx, ok := chooseSingletonMergeTarget(width, height, maxCage, normalized, singletonIdx, rng)132137 if !ok {@@ -142,6 +147,15 @@ func normalizeSingletonCages(width, height, maxCage int, cages []Cage, profile g
142147 return renumberCages(normalized)143148 }144149 150+func hasOversizeCage(cages []Cage, maxCage int) bool {151+ for _, cage := range cages {152+ if len(cage.Cells) > maxCage {153+ return true154+ }155+ }156+ return false157+}158+145159 func countSingletonCages(cages []Cage) int {146160 count := 0147161 for _, cage := range cages {@@ -248,6 +248,9 @@ func TestSparseModesGenerateUniquePuzzlesWithLimitedSingletons(t *testing.T) {
248248 if got := countSingletonCages(puzzle.Cages); got > 1 {249249 t.Fatalf("%s singleton cages = %d, want <= 1", mode.Title(), got)250250 }251+ if hasOversizeCage(puzzle.Cages, mode.MaxCage) {252+ t.Fatalf("%s generated a cage larger than max size %d", mode.Title(), mode.MaxCage)253+ }251254 252255 if countZeroGivenCages(puzzle) > 0 {253256 sawZeroGivenCage = true