Skip to content

florian-mollin/lights-out-solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Java Lights Out Solver

Examples

Example 1 : compute all solutions

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

Example 2 : compute first solution

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

Example 3 : custom grids

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

Example 4 : custom pattern

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

For fun

Fun 1

Start grid
(250×250)
Pattern
(Classic)
➡️Final grid
(250×250)
Solution

Fun 2

Start grid
(250×250)
Pattern
(Custom)
➡️Final grid
(250×250)
Solution

About

Java Lights Out Solver (with defined grids and pattern)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages