public int GetDistance(Ride ride)
        {
            if (!distanceCache.ContainsKey(ride.Id))
            {
                (int x, int y) = Position();

                distanceCache[ride.Id] = Manhattan.Distance(x, y, ride.StartX, ride.StartY);
            }

            return(distanceCache[ride.Id]);
        }
Exemple #2
0
        public Ride(int id, int startX, int startY, int endX, int endY, int start, int end)
        {
            this.Id     = id;
            this.StartX = startX;
            this.StartY = startY;
            this.EndX   = endX;
            this.EndY   = endY;
            this.Start  = start;
            this.End    = end;

            this.Distance = Manhattan.Distance(this.StartX, this.StartY, this.EndX, this.EndY);
        }
Exemple #3
0
        public bool CanStart(Ride ride)
        {
            var earliestStart = EarliestStart(ride);

            if (earliestStart <= ride.Start)
            {
                return(false);
            }

            if (earliestStart < 0)
            {
                return(false);
            }

            var fromStart = Manhattan.Distance(ride.StartX, ride.StartY, 0, 0);

            return(earliestStart - fromStart > 0);
        }
Exemple #4
0
 public int GetDistance(int x, int y)
 {
     return(Manhattan.Distance(StartX, StartY, x, y));
 }
Exemple #5
0
        public int Distance(Ride ride)
        {
            var lastRide = rides.LastOrDefault();

            return(Manhattan.Distance(lastRide.StartX, lastRide.StartY, ride.EndX, ride.EndY));
        }