public void SetInitialDirection()
        {
            InitialOrientation = new Compass(CurrentOrientation.Orientation);
            switch (CurrentOrientation.Orientation)
            {
            case Compass.OrientationType.North:
                FaceNorth();
                break;

            case Compass.OrientationType.East:
                FaceEast();
                break;

            case Compass.OrientationType.West:
                FaceWest();
                break;

            case Compass.OrientationType.South:
                FaceSouth();
                break;
            }
        }
Esempio n. 2
0
        public Program GenerateProgram()
        {
            Program program = new Program();

            if (PositionList.Count <= 1)
            {
                return(program);
            }

            Position current = PositionList[0], next = PositionList[1];
            Compass  compass = new Compass();

            Position.NeighbourType neighbourType = current.GetNeighbourType(next);

            switch (neighbourType)
            {
            case Position.NeighbourType.Top:
                compass.Orientation = Compass.OrientationType.North;
                break;

            case Position.NeighbourType.Right:
                compass.Orientation = Compass.OrientationType.East;
                break;

            case Position.NeighbourType.Bottom:
                compass.Orientation = Compass.OrientationType.South;
                break;

            case Position.NeighbourType.Left:
                compass.Orientation = Compass.OrientationType.West;
                break;
            }

            StartCompass = new Compass(compass.Orientation);

            for (int i = 1; i < PositionList.Count; i++)
            {
                next          = PositionList[i];
                neighbourType = current.GetNeighbourType(next, compass);

                switch (neighbourType)
                {
                case Position.NeighbourType.Top:
                    program.AddInstruction(Instruction.Type.Forward);
                    break;

                case Position.NeighbourType.Right:
                    program.AddInstruction(Instruction.Type.TurnRight);
                    compass.TurnRight();
                    program.AddInstruction(Instruction.Type.Forward);
                    break;

                case Position.NeighbourType.Left:
                    program.AddInstruction(Instruction.Type.TurnLeft);
                    compass.TurnLeft();
                    program.AddInstruction(Instruction.Type.Forward);
                    break;
                }
                current = next;
            }
            return(program);
        }