Exemple #1
0
        public override Path solve(Maze maze)
        {
            LinkedList <ScoredCoordinates> closedSet = new LinkedList <ScoredCoordinates>();
            LinkedList <ScoredCoordinates> openSet   = new LinkedList <ScoredCoordinates>();

            ScoredCoordinates start = new ScoredCoordinates(maze.startPosition);

            start.f = start.heuristic_cost(maze.endPosition);

            openSet.AddFirst(start);

            while (openSet.Count >= 1)
            {
                ScoredCoordinates current = openSet.First();
                foreach (ScoredCoordinates node in openSet)
                {
                    if (node.f < current.f)
                    {
                        current = node;
                    }
                }

                if (current.Equals(maze.endPosition))
                {
                    // Return Reconstructed path
                    Path reconstructedPath = new Path(maze.startPosition);

                    while (current != null)
                    {
                        reconstructedPath.AddAfter(reconstructedPath.First, current);
                        current = current.cameFrom;
                    }

                    return(reconstructedPath);
                }

                openSet.Remove(current);
                closedSet.AddLast(current);

                foreach (ScoredCoordinates neighbor in getNeighbors(current, maze))
                {
                    if (closedSet.Contains(neighbor))
                    {
                        continue;
                    }

                    // Selecting the node in the openSet if it was already added
                    bool isNew = true;
                    ScoredCoordinates exploredNeighbor = neighbor;

                    foreach (ScoredCoordinates openSetMember in openSet)
                    {
                        if (neighbor.Equals(openSetMember))
                        {
                            exploredNeighbor = openSetMember;
                            isNew            = false;
                            break;
                        }
                    }

                    if (isNew)
                    {
                        openSet.AddLast(neighbor);
                    }

                    double tentative_g = current.g + maze.valueAt(exploredNeighbor);
                    if (tentative_g >= exploredNeighbor.g)
                    {
                        continue;
                    }

                    exploredNeighbor.cameFrom = current;
                    exploredNeighbor.g        = tentative_g;
                    exploredNeighbor.f        = exploredNeighbor.g + exploredNeighbor.heuristic_cost(maze.endPosition);
                }
            }

            return(null);
        }
        public override Path solve(Maze maze)
        {
            //Start the mapping of the whole maze
            int[] dataCoord = { maze.endPosition.x, maze.endPosition.y, 0 };
            mainQueue.Enqueue(dataCoord);
            char[,] map  = new char[maze.getHeight(), maze.getWidth()];
            currentCoord = new Coordinates(maze.endPosition.x, maze.endPosition.y);

            //    //Continue mapping of the whole maze
            //    for (int i = 0; i < NUMBER_OF_POTENTIAL_DIRECTION; i++){
            //        if(currentCoord.x == 0)

            //    }
            //    //maze[][]


            //Build and return shortest path
            Path path = new Path(maze.startPosition);

            //Build...
            return(path);
            //}

            //public bool checkUpperLeft(Maze maze)
            //{
            //    if (maze.valueAt(currentCoord.x+1))
            //    {

            //    }
            //    else
            //    {

            //    }
            //}
            //public bool checkUpper(Maze maze)
            //{

            //}
            //public bool checkUpperRight(Maze maze)
            //{

            //}
            //public bool checkLeft(Maze maze)
            //{

            //}
            //public bool checkRight(Maze maze)
            //{

            //}
            //public bool checkUnderLeft(Maze maze)
            //{

            //}
            //public bool checkUnder(Maze maze)
            //{

            //}
            //public bool checkUnderRight(Maze maze)
            //{

            //}
        }
 public abstract Path solve(Maze maze);