コード例 #1
0
ファイル: Maze.cs プロジェクト: IMANE6HHGS/MazeMaker
        public Path findLongestStartAndFinish()
        {
            int  helped = 0, notHelped = 0;
            Path max   = new Path(new Point(0, 0));
            int  total = Width * Height;

            this.UpdateStatus(Status.Starting("Starting optimising start / end"));


            PathCollection[] fromPointCol = new PathCollection[total];
            for (int t = 0; t < total; t++)
            {
                fromPointCol[t] = new PathCollection();
            }

            for (int t = 0; t < (total - 1); t++)
            {
                Point          to         = new Point(t % Width, t / Width);
                PathCollection toPointCol = new PathCollection();

                for (int f = total - 1; f >= (t + 1); f--)
                {
                    Point from = new Point(f % Width, f / Width);

                    //if we are starting on a previous path, then we know a longer version exists
                    if (fromPointCol[f].Contains(to))
                    {
                        helped += f;
                        break;
                    }

                    if (!toPointCol.Contains(from))
                    {
                        Path path = findShortestPath(from, to);
                        if (path != null)
                        {
                            if (path.Count > max.Count)
                            {
                                max = path;
                            }
                            toPointCol.Add(path);
                            fromPointCol[f].Add(path);
                        }
                        notHelped++;
                    }
                    else
                    {
                        helped++;
                    }
                }
                //this.UpdateStatus(Status.UpdateLoop(i, total));
                this.UpdateStatus(Status.UpdateLoopMessage("" + (helped / (double)(helped + notHelped)) + "effective ", t, total));
            }

            this.UpdateStatus(Status.Done());
            return(max);
        }
コード例 #2
0
        public static List <Path> findShortest(Maze maze,
                                               List <Point> starts,
                                               List <Point> ends,
                                               PathCollection preSolves,
                                               int maxSolves = 1000)
        {
            List <Path> paths     = new List <Path>();
            List <Path> solutions = new List <Path>();

            foreach (Point start in starts)
            {
                paths.Add(new Path(start));
            }

            bool moreSearchingNeeded = true;

            while (moreSearchingNeeded && (solutions.Count < maxSolves))
            {
                List <Path> nextPaths = new List <Path>();
                foreach (Path path in paths)
                {
                    List <Path> continuences = path.findNextPossiblePaths(maze);
                    nextPaths.AddRange(continuences);
                }
                paths = nextPaths;

                moreSearchingNeeded = false;
                foreach (Path path in paths)
                {
                    if (!ends.Contains(path.CurrentPos))//!path.hasSolvedMaze(maze))
                    {
                        moreSearchingNeeded = true;
                    }
                    else
                    {
                        solutions.Add(path);
                        //paths.Remove(path);
                    }
                }
            }

            return(solutions);
        }
コード例 #3
0
 public PathCollection(PathCollection other) : base(other)
 {
     existingPoints = new Dictionary <Point, Path>(other.existingPoints);
 }