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); }
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); }
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); }
public int GetScoreAndBonus(Ride ride) { (var score, var bonus, var extraSteps) = Calculate(ride); return(score + bonus); }
public bool CanFinish(Ride ride) { return(CurrentStep + GetDistance(ride) + ride.Distance < ride.End); }
public int Distance(Ride ride) { var lastRide = rides.LastOrDefault(); return(Manhattan.Distance(lastRide.StartX, lastRide.StartY, ride.EndX, ride.EndY)); }
public void AssignRide(Ride ride) { CurrentStep = EarliestStart(ride); rides.Add(ride); }
public void SetEnd(Ride ride) { this.rides.Add(ride); this.CurrentStep = ride.End - ride.Distance; }
public int EarliestStart(Ride ride) { var extra = Distance(ride); return(Math.Min(CurrentStep - extra - ride.Distance, ride.End - 1 - ride.Distance)); }