private SolverState PerformStandardTest(Puzzle puzzle, ExitConditions exit = null) { exit = exit ?? new ExitConditions { Duration = TimeSpan.FromSeconds(60), StopOnSolution = true, TotalNodes = int.MaxValue, TotalDead = int.MaxValue }; // arrange var solver = new SingleThreadedReverseSolver(new SolverNodeFactoryTrivial()); var command = new SolverCommand { Puzzle = puzzle.Clone(), Report = new XUnitOutput(outp), ExitConditions = exit, Inspector = node => { if (node.GetHashCode() == 929793) { outp.WriteLine(node.ToString()); return(true); } return(false); } }; // act var result = solver.Init(command); solver.Solve(result); // Console.WriteLine(result.ExitDescription); // Console.WriteLine(SolverHelper.GenerateSummary(result)); result.ThrowErrors(); // assert Assert.NotNull(result); foreach (var solution in result.SolutionsNodes) { var p = solution.PathToRoot().ToList(); p.Reverse(); } foreach (var sol in result.Solutions) { Assert.True(SolverHelper.CheckSolution(command.Puzzle, sol, out var error), "Solution is INVALID! " + error); } return(result); }
public void ReverseSingle() { var solverCommand = new SolverCommand() { Puzzle = Puzzle.Builder.DefaultTestPuzzle(), ExitConditions = ExitConditions.Default3Min(), }; var solver = new SingleThreadedReverseSolver(new SolverNodeFactoryTrivial()); var solverState = solver.Init(solverCommand); solver.Solve(solverState); if (!solverState.HasSolution) { throw new Exception(); } }
private SolverState PerformStandardTest(Puzzle puzzle, ExitConditions exit = null) { exit = exit ?? new ExitConditions { Duration = TimeSpan.FromSeconds(60), StopOnSolution = true, TotalNodes = int.MaxValue, TotalDead = int.MaxValue }; // arrange var solver = new SingleThreadedReverseSolver(new SolverNodeFactoryTrivial()); var command = new SolverCommand { Puzzle = puzzle.Clone(), Report = Console.Out, ExitConditions = exit }; // act var result = solver.Init(command); solver.Solve(result); Console.WriteLine(result.ExitDescription); Console.WriteLine(SolverHelper.GenerateSummary(result)); result.ThrowErrors(); // assert Assert.NotNull(result); foreach (var solution in result.SolutionsNodes) { var p = solution.PathToRoot(); p.Reverse(); } foreach (var sol in result.Solutions) { Console.WriteLine("Path: {0}", sol); string error = null; Assert.True(SolverHelper.CheckSolution(command.Puzzle, sol, out error), "Solution is INVALID! " + error); } return(result); }