Exemplo n.º 1
0
        public string Execute(string[] args, TcpClient client = null)
        {
            string name      = args[0];
            string algorithm = args[1];
            //get the maze from the model
            Maze mazeFromModel = this.model.GetMaze(name);

            if (mazeFromModel == null)
            {
                //return there is no maze
            }

            //create new adapter
            adapter = new MazeAdapter <Position>(mazeFromModel);

            //if 0 then bfs, if 1 dfs, otherwise print error
            if (algorithm.Equals("0"))
            {
                ser = new BestFirstSearch <Position>();
            }
            else if (algorithm.Equals("1"))
            {
                ser = new DFS <Position>();
            }
            else
            {
                //return algorithm input invalid
            }

            sol = ser.search(adapter);
            Console.WriteLine(sol.Path.Count());
            Console.WriteLine(sol.Path.Count());
            solAdapter = new SolutionAdapter(sol);
            //add the solved maze to the solved mazes dictionary in the model
            this.model.AddSolvedMaze(name, solAdapter.ToString());
            solJson = new SolutionJson(name, solAdapter.ToString(), ser.getNumberOfNodesEvaluated());
            return(solJson.solveToJSON());
        }
Exemplo n.º 2
0
        public JObject SolveMaze(string name)
        {
            Maze mazeFromModel = GetMaze(name);
            //create new adapter
            Maze maze = GetMaze(name);

            adapter = new MazeAdapter <Position>(maze);
            ser     = new BestFirstSearch <Position>();
            sol     = ser.search(adapter);
            Console.WriteLine(sol.Path.Count());
            Console.WriteLine(sol.Path.Count());
            solAdapter = new SolutionAdapter(sol);
            JObject mazeSolutionObj = new JObject();

            mazeSolutionObj["Name"]     = name;
            mazeSolutionObj["Solution"] = solAdapter.ToString();
            return(mazeSolutionObj);
        }