/// <summary> /// execute commande and return solution at json format. /// </summary> /// <param name="args">input from user</param> /// <param name="client">client's data</param> /// <returns>solution - string at json format</returns> public string Execute(string[] args, TcpClient client) { string name; int algo; try { name = args[0]; algo = int.Parse(args[1]); if (algo != 1 && algo != 0) { return("Error at algorithem numeber parameter: 0 - for bfs, 1 - for dfs"); } } catch (Exception) { Console.Error.WriteLine("Error in parameters of solve comand"); return("Error in parameters of solve comand"); } Solution <MazeLib.Position> solution = model.Solve(name, algo); if (solution == null) { return("name of maze doesn't exist at maze single player pool"); } SolutionRepresent <MazeLib.Direction, MazeLib.Position, int> solRepresent = new MazeSolRepreset(solution); solRepresent.ConvertSolution(); return(solRepresent.ToJSON()); }
/// <summary> /// Roy's example. /// </summary> public static void test() { string json = @"{ 'Name': 'mymaze', 'Maze': '0001010001010101110101010000010111111101000001000111010101110001010001011111110100000000011111111111', 'Rows': 10, 'Cols': 10, 'Start': { 'Row': 0, 'Col': 4 }, 'End': { 'Row': 0, 'Col': 0 } }"; Maze maze = Maze.FromJSON(json); Console.Write(maze.ToString()); Adapter <Position> adapter = new MazeToSearchableAdapter <Position>(maze); ISearchable <Position> searchableMaze = new Searchable <Position, Direction>(adapter); ISearcher <Position> bfs = new Bfs <Position>(); ISearcher <Position> dfs = new Dfs <Position>(); Solution <Position> solBfs = bfs.Search(searchableMaze); Solution <Position> solDfs = dfs.Search(searchableMaze); Console.WriteLine("bfs " + solBfs.NodesEvaluated.ToString()); SolutionRepresent <MazeLib.Direction, MazeLib.Position, int> solRepresent = new MazeSolRepreset(solBfs); solRepresent.ConvertSolution(); Console.WriteLine("bfs sol " + solRepresent.ToJSON()); Console.WriteLine("dfs " + solDfs.NodesEvaluated); Console.ReadKey(); }