Start grid (4×4) | Pattern (Classic) | ➡️ | Final grid (4×4) |
---|---|---|---|
GridInterface startGrid = GridUtils.getEmptyGrid(4, 4);
GridInterface finalGrid = GridUtils.getFullGrid(4, 4);
PatternInterface pattern = PatternUtils.getClassicPattern();
Solver solver = new Solver(startGrid, finalGrid, pattern);
// compute all solutions
Solutions solutions = solver.solve();
System.out.println(solutions);
Solutions | |||||||
---|---|---|---|---|---|---|---|
Start grid (20×20) | Pattern (Classic) | ➡️ | Final grid (20×20) |
---|---|---|---|
GridInterface startGrid = GridUtils.getEmptyGrid(20, 20);
GridInterface finalGrid = GridUtils.getFullGrid(20, 20);
PatternInterface pattern = PatternUtils.getClassicPattern();
Solver solver = new Solver(startGrid, finalGrid, pattern);
// compute only the first one solution (if exists)
Optional<Solution> firstSolution = solver.findFirstSolution();
firstSolution.ifPresent(System.out::println);
First solution |
---|
Start grid (3×3 custom) | Pattern (Classic) | ➡️ | Final grid (3×3 custom) |
---|---|---|---|
// custom start grid
GridInterface startGrid = GridUtils.getGridWithSomeActivatedCoords(3, 3,
Coord.of(0, 0), Coord.of(1, 0), Coord.of(2, 2)
);
// custom final grid
GridInterface finalGrid = GridUtils.getGridWithSomeActivatedCoords(3, 3,
Coord.of(0, 1), Coord.of(1, 0), Coord.of(1, 1),
Coord.of(1, 2), Coord.of(2, 1)
);
PatternInterface pattern = PatternUtils.getClassicPattern();
Solver solver = new Solver(startGrid, finalGrid, pattern);
Solutions solutions = solver.solve();
System.out.println(solutions);
Solutions |
---|
Start grid (42×42) | Pattern (Custom) | ➡️ | Final grid (42×42) |
---|---|---|---|
GridInterface startGrid = GridUtils.getEmptyGrid(42, 42);
// custom pattern
PatternInterface pattern = (coord) -> {
return new HashSet<>(Arrays.asList(
coord.add(Coord.of(1, 1)), coord.add(Coord.of(-1, -1)),
coord.add(Coord.of(-1, 1)), coord.add(Coord.of(1, -1)),
coord.add(Coord.of(1, 0)), coord.add(Coord.of(0, 1)),
coord.add(Coord.of(-1, 0)), coord.add(Coord.of(0, -1))
));
};
// by default, finalGrid is full
Solver solver = new Solver(startGrid, pattern);
Optional<Solution> firstSolution = solver.findFirstSolution();
firstSolution.ifPresent(System.out::println);
First solution |
---|
Start grid (250×250) | Pattern (Classic) | ➡️ | Final grid (250×250) |
---|---|---|---|
Solution |
---|
Start grid (250×250) | Pattern (Custom) | ➡️ | Final grid (250×250) |
---|---|---|---|
Solution |
---|