コード例 #1
0
        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();
                }
            }
        }
コード例 #2
0
ファイル: Puzzle.cs プロジェクト: bvanreeven/CargoBotSolver
 public Puzzle(PuzzleData puzzleData)
 {
     initialStage = Stage.CreateStage(puzzleData.GrapplerPosition, puzzleData.Setup);
     goalStage = Stage.CreateStage(0, puzzleData.Goal);
     toolbox = null; // XXX Toolbox.CreateToolbox(puzzleData.Toolbox);
 }
コード例 #3
0
 public Snapshot(Stage stage, Stack<ProgramCounter> stack)
 {
     this.stage = stage;
     this.stack = new Stack<ProgramCounter>(stack);
 }
コード例 #4
0
 //readonly HashSet<Snapshot> snapshots = new HashSet<Snapshot>();
 public Simulator(Puzzle puzzle, Solution solution)
 {
     this.puzzle = puzzle;
     this.solution = solution;
     this.currentStage = puzzle.InitialStage;
 }
コード例 #5
0
ファイル: Stage.cs プロジェクト: bvanreeven/CargoBotSolver
        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;
        }