Esempio n. 1
0
        public static Solver ParseInput(IList <string> input)
        {
            var solver = new Solver();

            int inputRowNumber = 0;

            input[inputRowNumber].FirstIs <int>(i => solver.Rows          = i);
            input[inputRowNumber].SecondIs <int>(i => solver.Columns      = i);
            input[inputRowNumber].ThirdIs <int>(i => solver.VehiclesCount = i);
            input[inputRowNumber].FourthIs <int>(i => solver.RidesCount   = i);
            input[inputRowNumber].FifthIs <int>(i => solver.Bonus         = i);
            input[inputRowNumber].SixthIs <int>(i => solver.TotalSteps    = i);
            inputRowNumber++;

            for (int i = 0; i < solver.VehiclesCount; i++)
            {
                var vehicle = new Vehicle
                {
                    Id = i
                };
                solver.Vehicles.Add(vehicle);
            }

            for (int index = 0; index < solver.RidesCount; index++)
            {
                var ride = new Ride();
                ride.Id = index;
                input[inputRowNumber].FirstIs <int>(startingRow => ride.StartingRow          = startingRow);
                input[inputRowNumber].SecondIs <int>(startingColumn => ride.StartingColumn   = startingColumn);
                input[inputRowNumber].ThirdIs <int>(finishingRow => ride.FinishingRow        = finishingRow);
                input[inputRowNumber].FourthIs <int>(finishingColumn => ride.FinishingColumn = finishingColumn);
                input[inputRowNumber].FifthIs <int>(earliestStart => ride.EarliestStart      = earliestStart);
                input[inputRowNumber].SixthIs <int>(latestFinish => ride.LatestFinish        = latestFinish);

                ride.InitPosition();

                solver.Rides.Add(ride);
                inputRowNumber++;
            }
            return(solver);
        }
        public int DoRide(Ride r)
        {
            int points  = 0;
            int endTime = CalcRide(r);

            if (endTime >= 0)
            {
                //add ride to list
                rides.Add(r.index);
                Xpos = r.xPosEnd;
                Ypos = r.yPosEnd;
                Time = endTime;
                int distance = Math.Abs(r.xPosStart - r.xPosEnd) + Math.Abs(r.yPosStart - r.yPosEnd);
                points += distance;
                if (r.timeStart + distance == Time)
                {
                    points += Program.bonus;
                }
            }

            return(points);
        }
        public int CalcWastedTime(Ride r)
        {
            int wastedTime = 0;
            int res        = -1;
            int maxTime    = r.timeEnd;

            // calc Time to reach start point
            int neededTime = Math.Abs(Xpos - r.xPosStart) + Math.Abs(Ypos - r.yPosStart);

            // calc Time to reach end point
            neededTime += Math.Abs(r.xPosStart - r.xPosEnd) + Math.Abs(r.yPosStart - r.yPosEnd);
            // see if it is even possible
            if (Time + neededTime > r.timeEnd)
            {
                return(int.MaxValue);
            }
            else
            {
                // calc time to wait for startTime
                wastedTime = r.timeStart - Time;
            }

            return(wastedTime);
        }
        static void Main(string[] args)
        {
            /*
             *  Important Variables
             */
            int maxRows;
            int maxColumns;
            int maxRides;
            int maxSteps;

            /*
             *  Read not fantastic stuff out of file
             */
            var inputFile = "";

            if (args.Length == 0)
            {
                Console.WriteLine("Missing parameter...");
                Console.ReadKey();
                Environment.Exit(0);
            }
            else
            {
                inputFile = args[0];
                Console.WriteLine($"Input Path = {inputFile}");
            }

            if (File.Exists(inputFile))
            {
                //read full input file
                string[] fullInput = File.ReadAllLines(inputFile);

                foreach (var s in fullInput)
                {
                    Console.WriteLine(s);
                }

                // the first line is giving us indication on how the issue should be solved
                // extract it to own variables
                int[] inputParameters = fullInput[0].Split(' ').Select(x => int.Parse(x)).ToArray();

                // Read first line parameters
                maxRows     = inputParameters[0];
                maxColumns  = inputParameters[1];
                maxVehicles = inputParameters[2];
                maxRides    = inputParameters[3];
                bonus       = inputParameters[4];
                maxSteps    = inputParameters[5];

                // Read all rides
                for (int i = 1; i <= maxRides; i++)
                {
                    int[] tmpIn   = fullInput[i].Split(' ').Select(x => int.Parse(x)).ToArray();
                    Ride  tmpRide = new Ride(tmpIn[0], tmpIn[2], tmpIn[1], tmpIn[3], tmpIn[4], tmpIn[5], i - 1);
                    allRides.Add(tmpRide);
                }

                // create all vehicles
                for (int i = 0; i < maxVehicles; i++)
                {
                    Vehicle tmpVehicle = new Vehicle(0, 0, 0);
                    allVehicles.Add(tmpVehicle);
                }



                /*
                 * Do fantastic Stuff
                 */

                int normalPoints;
                int sortedPoints;
                //normalPoints = doCrazyStuffNormal();
                //resetVehicles();
                sortedPoints = doCrazyStuffSorted();
                //if (normalPoints > sortedPoints)
                //{
                //resetVehicles();
                //doCrazyStuffNormal();
                //}


                /*
                 * Write fantastic stuff to file
                 */
                WriteToFile(allVehicles, args[0] + ".out");
            }
        }
Esempio n. 5
0
 public void SetNewRide(Ride newRide)
 {
     ride          = newRide;
     remainingRoad = ride.Length + (Math.Abs(CurrentPosition.Row - ride.Start.Row) + Math.Abs(CurrentPosition.Column - ride.Start.Column));
     IsBusy        = true;
 }