/// <summary> /// Gets the element to the left, it is the Next pointer of the linked list Node /// and in the case of the last element then it is the first element /// <param name="currentOrientation">Orientation to move from</param> /// <returns>Orientation after moving to the left</returns> public static Orientation ToLeft(Orientation currentOrientation) { if (orientationsList.First.Value == currentOrientation) return orientationsList.Last.Value; return orientationsList.Find(currentOrientation).Previous.Value; }
/// <summary> /// Type constructor initializes the 4 directions object (just to have a handy pointer to them) /// and adds them in order to the cyclic doubly linked list /// </summary> static OrientationsHandler( ) { orientationsList = new LinkedList<Orientation>(); North = new Orientation(Directions.North); South = new Orientation(Directions.South); East = new Orientation(Directions.East); West = new Orientation(Directions.West); orientationsList.AddFirst(North); orientationsList.AddLast(East); orientationsList.AddLast(South); orientationsList.AddLast(West); }
/// <summary> /// Gets the element to the right, it is the Next pointer of the linked list Node /// and in the case of the last element then it is the first element /// </summary> /// <param name="currentOrientation">Orientation to move from</param> /// <returns>Orientation after moving to the right</returns> public static Orientation ToRight(Orientation currentOrientation) { if (orientationsList.Last.Value == currentOrientation) return orientationsList.First.Value; return orientationsList.Find(currentOrientation).Next.Value; }
/// <summary> /// Determines if the Robot is about to fall off the face of the Mars /// </summary> /// <param name="CurrentPosition">Current position of the robot</param> /// <param name="CurrentOrientation">Current orientation of the robot</param> /// <returns></returns> private bool WillFallOffMars(Position CurrentPosition, Orientation CurrentOrientation) { bool willFall = false; //checks for edge cases after which the robot will fall if ( (CurrentOrientation == OrientationsHandler.North && CurrentPosition.Y == Planet.UpperY) || (CurrentOrientation == OrientationsHandler.East && CurrentPosition.X == Planet.UpperX) || (CurrentOrientation == OrientationsHandler.South && CurrentPosition.Y == 0) || (CurrentOrientation == OrientationsHandler.West && CurrentPosition.X == 0) ) { willFall = true; } return willFall; }