示例#1
0
        /// <summary>
        /// Solves the maze.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="typeAlgo">The type algo.</param>
        /// <returns></returns>
        public SolveInfo SolveMaze(string name, string typeAlgo)
        {
            Maze                maze           = singleplayerMazeList[name];
            MazeAdapter         mazeSearchable = new MazeAdapter(maze);     // Isearchable
            var                 temp           = new CompareStates <Position>();
            Solution <Position> solution       = null;
            int                 nodesEvaluated = 0;

            if (solutionsList.ContainsKey(maze))
            {
                return(solutionsList[maze]);
            }

            // find solution of the maze:
            switch (typeAlgo)
            {
            case "0":
                BFS <Position> bfs = new BFS <Position>(temp);
                solution       = bfs.Search(mazeSearchable);
                nodesEvaluated = bfs.GetNumberOfNodesEvaluated();
                break;

            case "1":
                DFS <Position> dfs = new DFS <Position>(temp);
                solution       = dfs.Search(mazeSearchable);
                nodesEvaluated = dfs.GetNumberOfNodesEvaluated();
                break;
            }
            SolveInfo solveInfo = new SolveInfo(nodesEvaluated, solution);

            // add the solution to the solutions dictionary
            solutionsList.Add(maze, solveInfo);
            return(solveInfo);
        }
示例#2
0
        /// <summary>
        /// Executes the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <param name="client">The client.</param>
        /// <returns></returns>
        public ConnectionInfo Execute(string[] args, TcpClient client = null)
        {
            string name = args[0];
            string algo = args[1];

            SolveInfo       solveInfo       = model.SolveMaze(name, algo);
            SolutionAdapter solutionAdapter = new SolutionAdapter(solveInfo.Solution);
            string          strSolution     = solutionAdapter.CreateString();

            JObject solutionObj = new JObject();

            solutionObj["Name"]           = name;
            solutionObj["Solution"]       = strSolution;
            solutionObj["NodesEvaluated"] = solveInfo.NodesEvaluated;

            ConnectionInfo connectionInfo = new ConnectionInfo();

            connectionInfo.Answer          = solutionObj.ToString();
            connectionInfo.CloseConnection = true;

            return(connectionInfo);
        }