public static IAlgorithm CreateAlgorithm(string name, Puzzle puzzle) { if (!algorithms.ContainsKey(name)) throw new ArgumentException("unknown algorithm name"); return algorithms[name](puzzle); }
public void CrashLeft() { var puzzle = new Puzzle(File.ReadAllText("../../Puzzles/Cargo101.json")); var solution = new Solution(); solution.F1.AddInstruction(InstructionType.Left); var simulator = new Simulator(puzzle, solution); Assert.AreEqual(SimulationResult.CrashedIntoLeftWall, simulator.Run()); }
public void DetectInfiniteLoop() { var puzzle = new Puzzle(File.ReadAllText("../../Puzzles/Cargo101.json")); var solution = new Solution(); solution.F1.AddInstruction(InstructionType.Down); solution.F1.AddInstruction(InstructionType.F1); var simulator = new Simulator(puzzle, solution); Assert.AreEqual(SimulationResult.InfiniteLoop, simulator.Run()); }
public void CallFunction() { var puzzle = new Puzzle(File.ReadAllText("../../Puzzles/Cargo101.json")); var solution = new Solution(); solution.F1.AddInstruction(InstructionType.F2); solution.F1.AddInstruction(InstructionType.Right); solution.F1.AddInstruction(InstructionType.F2); solution.F2.AddInstruction(InstructionType.Down); var simulator = new Simulator(puzzle, solution); Assert.AreEqual(SimulationResult.Solved, simulator.Run()); }
public void CrashIntoBoxes() { var puzzle = new Puzzle(File.ReadAllText("../../Puzzles/WalkingPiles.json")); var solution = new Solution(); solution.F1.AddInstruction(InstructionType.Down); solution.F1.AddInstruction(InstructionType.Right); solution.F1.AddInstruction(InstructionType.Down); solution.F1.AddInstruction(InstructionType.Left); solution.F1.AddInstruction(InstructionType.F1); var simulator = new Simulator(puzzle, solution); Assert.AreEqual(SimulationResult.CrashedIntoBoxes, simulator.Run()); }
public Solver(Puzzle puzzle, IAlgorithm algorithm) { this.puzzle = puzzle; this.algorithm = algorithm; }
public void EmptySolution() { var puzzle = new Puzzle(File.ReadAllText("../../Puzzles/Cargo101.json")); var solution = new Solution(); var simulator = new Simulator(puzzle, solution); Assert.AreEqual(SimulationResult.Finished, simulator.Run()); }
//readonly HashSet<Snapshot> snapshots = new HashSet<Snapshot>(); public Simulator(Puzzle puzzle, Solution solution) { this.puzzle = puzzle; this.solution = solution; this.currentStage = puzzle.InitialStage; }