Beispiel #1
0
        public string Execute(string[] args, TcpClient client)
        {
            string       name = args[1];
            int          alg  = int.Parse(args[2]);
            MazeSolution ms   = model.SolveMaze(name, alg);

            if (ms == null)
            {
                return("maze does not exist");
            }
            return(ms.ToJSON());
        }
Beispiel #2
0
        /// <summary>
        /// Solves the maze.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="alg">The alg.</param>
        /// <returns>MazeSolution.</returns>
        public MazeSolution SolveMaze(string name, int alg)
        {
            Solution <Position> sol;
            int nodesEvaluated;

            if (this.mazeSolutionCache.ContainsKey(name))
            {
                return(this.mazeSolutionCache[name]);
            }

            if (this.mazeCache.ContainsKey(name))
            {
                Maze m = this.mazeCache[name];
                if (alg == 0)
                {
                    BFS <Position>         bfs     = new BFS <Position>();
                    ISearchable <Position> newMaze = new MazeAdapter(m);
                    sol            = bfs.Search(newMaze);
                    nodesEvaluated = bfs.GetNumOfNodesEvaluated();
                }
                else
                {
                    DFS <Position>         dfs     = new DFS <Position>();
                    ISearchable <Position> newMaze = new MazeAdapter(m);
                    sol            = dfs.Search(newMaze);
                    nodesEvaluated = dfs.GetNumOfNodesEvaluated();
                }

                State <Position> .StatePool.ClearPool();

                MazeSolution ms = new MazeSolution(sol, name, nodesEvaluated);
                ms.SolutionPath();
                this.mazeSolutionCache.Add(name, ms);
                return(ms);
            }
            else
            {
                return(null);
            }
        }