public BestElevatorInfo checkBestElevator(int scoreToCheck, Elevator newElevator, BestElevatorInfo bestElevatorInfo, int floor)
 {
     if (scoreToCheck < bestElevatorInfo.bestScore)
     {
         bestElevatorInfo.bestScore    = scoreToCheck;
         bestElevatorInfo.bestElevator = newElevator;
         bestElevatorInfo.referenceGap = Math.Abs(newElevator.currentFloor - floor);
     }
     else if (bestElevatorInfo.bestScore == scoreToCheck)
     {
         int gap = Math.Abs(newElevator.currentFloor - floor);
         if (bestElevatorInfo.referenceGap > gap)
         {
             bestElevatorInfo.bestScore    = scoreToCheck;
             bestElevatorInfo.bestElevator = newElevator;
             bestElevatorInfo.referenceGap = gap;
         }
     }
     return(bestElevatorInfo);
 }
        //We use a score system depending on the current elevators state. Since the bestScore and the referenceGap are
        //higher values than what could be possibly calculated, the first elevator will always become the default bestElevator,
        //before being compared with to other elevators. If two elevators get the same score, the nearest one is prioritized.
        public Elevator findBestElevator(int floor, string direction)
        {
            int    requestedFloor     = floor;
            string requestedDirection = direction;
            var    bestElevatorInfo   = new BestElevatorInfo(null, 6, 1000000);

            if (requestedFloor == 1)
            {
                foreach (Elevator elevator in this.elevatorsList)
                {
                    if (1 == elevator.currentFloor && elevator.status == "stopped")
                    {
                        this.checkBestElevator(1, elevator, bestElevatorInfo, requestedFloor);
                    }
                    else if (1 == elevator.currentFloor && elevator.status == "idle")
                    {
                        this.checkBestElevator(2, elevator, bestElevatorInfo, requestedFloor);
                    }
                    else if (1 > elevator.currentFloor && elevator.direction == "up")
                    {
                        this.checkBestElevator(3, elevator, bestElevatorInfo, requestedFloor);
                    }
                    else if (1 < elevator.currentFloor && elevator.direction == "down")
                    {
                        this.checkBestElevator(3, elevator, bestElevatorInfo, requestedFloor);
                    }
                    else if (elevator.status == "idle")
                    {
                        this.checkBestElevator(4, elevator, bestElevatorInfo, requestedFloor);
                    }
                    else
                    {
                        this.checkBestElevator(5, elevator, bestElevatorInfo, requestedFloor);
                    }
                }
            }
            else
            {
                foreach (Elevator elevator in this.elevatorsList)
                {
                    if (requestedFloor == elevator.currentFloor && elevator.status == "stopped" && requestedDirection == elevator.direction)
                    {
                        this.checkBestElevator(1, elevator, bestElevatorInfo, requestedFloor);
                    }
                    else if (requestedFloor > elevator.currentFloor && elevator.direction == "up" && requestedDirection == "up")
                    {
                        this.checkBestElevator(2, elevator, bestElevatorInfo, requestedFloor);
                    }
                    else if (requestedFloor < elevator.currentFloor && elevator.direction == "down" && requestedDirection == "down")
                    {
                        this.checkBestElevator(2, elevator, bestElevatorInfo, requestedFloor);
                    }
                    else if (elevator.status == "idle")
                    {
                        this.checkBestElevator(3, elevator, bestElevatorInfo, requestedFloor);
                    }
                    else
                    {
                        this.checkBestElevator(4, elevator, bestElevatorInfo, requestedFloor);
                    }
                }
            }
            return(bestElevatorInfo.bestElevator);
        }