Example #1
0
        private (int score, int bonus, int extraSteps) Calculate(Ride ride)
        {
            int score      = ride.Distance;
            int extraSteps = GetDistance(ride);
            int bonus      = 0;

            int start = CurrentStep + extraSteps;

            if (start <= ride.Start)
            {
                bonus       = this.bonus;
                extraSteps += ride.Start - start;
            }

            return(score, bonus, extraSteps);
        }
Example #2
0
        public int GetRideScore(Ride ride)
        {
            var earliestStart = CurrentStep + GetDistance(ride);
            var score         = ride.Start - earliestStart;

            if (score == 0)
            {
                return(bonus);
            }

            if (score < 0)
            {
                return(bonus - score);
            }

            return(score);
        }
Example #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);
        }
Example #4
0
        public int GetScoreAndBonus(Ride ride)
        {
            (var score, var bonus, var extraSteps) = Calculate(ride);

            return(score + bonus);
        }
Example #5
0
 public bool CanFinish(Ride ride)
 {
     return(CurrentStep + GetDistance(ride) + ride.Distance < ride.End);
 }
Example #6
0
        public int Distance(Ride ride)
        {
            var lastRide = rides.LastOrDefault();

            return(Manhattan.Distance(lastRide.StartX, lastRide.StartY, ride.EndX, ride.EndY));
        }
Example #7
0
        public void AssignRide(Ride ride)
        {
            CurrentStep = EarliestStart(ride);

            rides.Add(ride);
        }
Example #8
0
        public void SetEnd(Ride ride)
        {
            this.rides.Add(ride);

            this.CurrentStep = ride.End - ride.Distance;
        }
Example #9
0
        public int EarliestStart(Ride ride)
        {
            var extra = Distance(ride);

            return(Math.Min(CurrentStep - extra - ride.Distance, ride.End - 1 - ride.Distance));
        }