private static void GetNextGridPoint_CountGreater1(ITrack track, ICar car, IList <Point> routeGridPoints, Point middleGridPoint,
                                                           out uint nrBacktracks, out Point gridPoint)
        {
            nrBacktracks = 0;
            // get candidate grid point set from car and then remove those that are invalid because of the track and remove the current point
            IList <Point> candidateGridPointsFiltered = ComputerDriverHelper.FilterCandidatePoints_RemoveInvalids
                                                            (track, car.GetCandidateGridPoints(routeGridPoints), routeGridPoints);

            if (candidateGridPointsFiltered.Count == 0)
            {
                // remark this is not a solution, because we do not have a better grid point
                nrBacktracks = 1;
                return;
            }

            // now find the "optimum" among the valid candidate grid points
            bool optimumPointFound = false;

            ComputerDriverHelper.GetNextGridPoint_CountGreater1_FindOptimum(routeGridPoints, candidateGridPointsFiltered, middleGridPoint, true, out optimumPointFound, out gridPoint);
            if (optimumPointFound == false)
            {
                // no optimum was found, this can happen because all grid points have an "invalid" direction
                // take one of the closest to the current point, ignoring the direction
                IList <Point> closestPoints2CurrentPoint = VectorMath.FindPointsInTheListClosest2FixPoint(routeGridPoints.Last(), candidateGridPointsFiltered);
                gridPoint = closestPoints2CurrentPoint[0];
            }
        }
Example #2
0
        private void GetNextGridPoint_CountGreater1_Backtrack(ITrack track, ICar car, IList <Point> routeGridPoints, Point middleGridPoint,
                                                              out uint nrBacktracks, out Point gridPoint)
        {
            bool foundOne = false;

            nrBacktracks = 0;                   // only a dummy value

            while (foundOne == false)
            {
                mBacktrackLevel++;
                nrBacktracks = mBacktrackLevel;

                // doing backtracking of routeGridPoints
                IList <Point> routeGridPointsLessTheLast = routeGridPoints.ToList();
                for (uint index = 0; index < mBacktrackLevel; index++)
                {
                    // add those that we backtrack to backtrack list so that we do not try them again
                    if (mBacktrackedRouteGridPoints.Contains(routeGridPointsLessTheLast[routeGridPointsLessTheLast.Count - 1]) == false)
                    {
                        mBacktrackedRouteGridPoints.Add(routeGridPointsLessTheLast[routeGridPointsLessTheLast.Count - 1]);
                    }
                    routeGridPointsLessTheLast.RemoveAt(routeGridPointsLessTheLast.Count - 1);
                }

                IList <Point> candidateGridPointsFilteredLessTheLast = ComputerDriverHelper.FilterCandidatePoints_RemoveInvalids
                                                                           (track, car.GetCandidateGridPoints(routeGridPointsLessTheLast), routeGridPointsLessTheLast);
                // remove the backtracked points
                IList <Point> nextFilter = candidateGridPointsFilteredLessTheLast.Except(mBacktrackedRouteGridPoints).ToList();
                if (nextFilter.Count > 0)
                {
                    foundOne = true;
                    bool carefulOptimumPointFound;
                    // we are too risky, use the careful computer driver -> option 4: closest = true
                    ComputerDriverHelper.GetNextGridPoint_CountGreater1_FindOptimum(routeGridPointsLessTheLast, nextFilter,
                                                                                    middleGridPoint, true, out carefulOptimumPointFound, out gridPoint);
                }
            }
        }