private void Step() { var pc = stack.Pop(); var instruction = solution.Functions[pc.FunctionIndex].InstructionAt(pc.InstructionIndex); if (instruction == null) return; stack.Push(pc.Increment()); if (currentStage.Matches(instruction.Condition)) { switch (instruction.Type) { case InstructionType.Right: currentStage = currentStage.Right(); break; case InstructionType.Down: currentStage = currentStage.Down(); break; case InstructionType.Left: currentStage = currentStage.Left(); break; case InstructionType.F1: stack.Push(new ProgramCounter(0, 0)); break; case InstructionType.F2: stack.Push(new ProgramCounter(1, 0)); break; case InstructionType.F3: stack.Push(new ProgramCounter(2, 0)); break; case InstructionType.F4: stack.Push(new ProgramCounter(3, 0)); break; default: throw new ArgumentOutOfRangeException(); } } }
public Puzzle(PuzzleData puzzleData) { initialStage = Stage.CreateStage(puzzleData.GrapplerPosition, puzzleData.Setup); goalStage = Stage.CreateStage(0, puzzleData.Goal); toolbox = null; // XXX Toolbox.CreateToolbox(puzzleData.Toolbox); }
public Snapshot(Stage stage, Stack<ProgramCounter> stack) { this.stage = stage; this.stack = new Stack<ProgramCounter>(stack); }
//readonly HashSet<Snapshot> snapshots = new HashSet<Snapshot>(); public Simulator(Puzzle puzzle, Solution solution) { this.puzzle = puzzle; this.solution = solution; this.currentStage = puzzle.InitialStage; }
public bool StacksEqual(Stage that) { if (this.stacks.Count != that.stacks.Count) return false; for (int i = 0; i < stacks.Count; i++) if (!stacks[i].SequenceEqual(that.stacks[i])) return false; return true; }