public RoverPosition CheckObstacle(bool moveRover, char command, RoverPosition pos, List <Tuple <int, int> > Obstacles) { if (command == 'F' || command == 'B') { int newXCoordinate = -1, newYCoordinate = -1; switch (command) { case 'F': switch (pos.Facing) { case 'N': newXCoordinate = pos.xCoordinate; newYCoordinate = pos.yCoordinate + 1; break; case 'S': newXCoordinate = pos.xCoordinate; newYCoordinate = pos.yCoordinate - 1; break; case 'W': newXCoordinate = pos.xCoordinate - 1; newYCoordinate = pos.yCoordinate; break; case 'E': newXCoordinate = pos.xCoordinate + 1; newYCoordinate = pos.yCoordinate; break; default: break; } break; case 'B': switch (pos.Facing) { case 'N': newXCoordinate = pos.xCoordinate; newYCoordinate = pos.yCoordinate - 1; break; case 'S': newXCoordinate = pos.xCoordinate; newYCoordinate = pos.yCoordinate + 1; break; case 'W': newXCoordinate = pos.xCoordinate + 1; newYCoordinate = pos.yCoordinate; break; case 'E': newXCoordinate = pos.xCoordinate - 1; newYCoordinate = pos.yCoordinate; break; default: break; } break; default: break; } //check if obstacle present on new coordinates (after wrapping) RoverPosition tempPosition = new RoverPosition() { xCoordinate = newXCoordinate, yCoordinate = newYCoordinate, Facing = pos.Facing, ObstaclePresent = false }; tempPosition = Wrapper.ApplyWrapperToPosition(tempPosition); Tuple <int, int> newPosition = new Tuple <int, int>(tempPosition.xCoordinate, tempPosition.yCoordinate); pos.ObstaclePresent = Obstacles.Contains(newPosition); if (moveRover && !pos.ObstaclePresent) { pos.xCoordinate = tempPosition.xCoordinate; pos.yCoordinate = tempPosition.yCoordinate; } } return(pos); }