-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08b59dc
commit 75cded2
Showing
12 changed files
with
217 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package solve | ||
|
||
import ( | ||
gs "github.com/deanveloper/gridspech-go" | ||
) | ||
|
||
// SolveAllTiles returns a channel which will return a TileSet of all tiles in g. | ||
func (g GridSolver) SolveAllTiles() <-chan gs.TileSet { | ||
solutionIter := make(chan gs.TileSet) | ||
|
||
go func() { | ||
defer close(solutionIter) | ||
|
||
for goalsAndDots := range mergeSolutionsIters(g.SolveGoals(), g.SolveDots()) { | ||
newGrid := g.Clone() | ||
newGrid.Grid.ApplyTileSet(goalsAndDots) | ||
newGrid.UnknownTiles.RemoveAll(goalsAndDots.ToTileCoordSet()) | ||
|
||
for joinsSolution := range newGrid.SolveJoins() { | ||
joinsSolved := newGrid.Clone() | ||
joinsSolved.Grid.ApplyTileSet(joinsSolution) | ||
joinsSolved.UnknownTiles.RemoveAll(joinsSolution.ToTileCoordSet()) | ||
|
||
for crownsSolution := range joinsSolved.SolveCrowns() { | ||
crownsSolved := joinsSolved.Clone() | ||
crownsSolved.Grid.ApplyTileSet(crownsSolution) | ||
crownsSolved.UnknownTiles.RemoveAll(crownsSolution.ToTileCoordSet()) | ||
|
||
if crownsSolved.Grid.Valid() { | ||
var merged gs.TileSet | ||
merged.Merge(goalsAndDots) | ||
merged.Merge(joinsSolution) | ||
merged.Merge(crownsSolution) | ||
solutionIter <- merged | ||
} | ||
} | ||
} | ||
} | ||
}() | ||
|
||
return solutionIter | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package solve_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/deanveloper/gridspech-go/solve" | ||
) | ||
|
||
func testSolveAllTilesAbstract(t *testing.T, level string, expectedSolutionsStrings []string, maxColors int) { | ||
t.Helper() | ||
|
||
testSolveAbstract(t, level, expectedSolutionsStrings, maxColors, solve.GridSolver.SolveAllTiles) | ||
} | ||
|
||
func TestSolveAllTiles_levelF10(t *testing.T) { | ||
const level = ` | ||
0 0 0 0 0 0 | ||
0 0e 0k 0 0 0 | ||
0 0 0k 0 0 0 | ||
0 0 0k 0 0 0 | ||
0 0 0k 0e 0 0 | ||
0j1 0e 0 0 0j1 0e | ||
` | ||
solutions := []string{ | ||
"111111|100001|111100|100010|101010|101110", | ||
"000000|011110|000011|011101|010101|010001", | ||
} | ||
|
||
testSolveAllTilesAbstract(t, level, solutions, 2) | ||
} |
Oops, something went wrong.