예제 #1
0
        /// <summary>
        /// Checks if there exists a solution by the name the client requested.
        ///     if so, it is fetched and sent to him.
        /// Otherwise, the model attempts the fetch the maze to solve.
        ///     if the maze does not exist, the function exists.
        ///     if the maze exists a solution is generated and sent to the client.
        /// </summary>
        /// <param name="from">the client that sent the command.</param>
        /// <param name="commandParsed">The parsed command.</param>
        public override void Execute(object from, string[] commandParsed)
        {
            string name        = commandParsed[1];
            int    type        = int.Parse(commandParsed[2]);
            int    commandType = 2;

            // check if there exists a solution
            string reply = model.GetMazeSolution(name);

            if (reply != null)
            {
                model.CompletedTask(from, new View.MessageEventArgs(reply));
                return;
            }

            // otherwise try to fetch the maze and generate a solution
            IMaze maze = model.GetMaze(name);

            if (maze == null)
            {
                return;
            }

            // maze exists but without a solution
            MazeSolverFactory solver = new MazeSolverFactory((WayToSolve)type);

            maze.SolveMaze(solver);
            string solution = maze.SolutionToString();

            // build reply
            reply = BuildReply(maze, name, solution, commandType);
            model.AddMazeSolution(name, reply);
            model.CompletedTask(from, new View.MessageEventArgs(reply));
        }
예제 #2
0
        static void Main(string[] args)
        {
            MazeFactory mazeFact = new MazeFactory(20, 32);

            MazeSolverFactory bfsSolverFact = new MazeSolverFactory(WayToSolve.BFS);
            MazeSolverFactory dfsSolverFact = new MazeSolverFactory(WayToSolve.BFS);

            WallBreakerFactory dfsWBreakerFact
                = new WallBreakerFactory(WallBreakerFactory.BreakingType.DFS);
            WallBreakerFactory randomPrimWBreakerFact
                = new WallBreakerFactory(WallBreakerFactory.BreakingType.Random);

            Console.WriteLine("Randomized DFS Generated Maze :");
            IMaze mazeDfs = mazeFact.GetMaze(dfsWBreakerFact);

            Console.WriteLine(mazeDfs.ToString());

            Console.WriteLine("\n\nRandomized DFS Maze Solution is :");
            mazeDfs.SolveMaze(new MazeSolverFactory(WayToSolve.DFS));
            Console.WriteLine(mazeDfs.SolutionToString());

            Console.WriteLine("\n\nRandomized Prim Generated Maze :");
            IMaze mazePrim = mazeFact.GetMaze(randomPrimWBreakerFact);

            Console.WriteLine(mazePrim.ToString());

            Console.WriteLine("\n\nRandomized Prim Maze Solution is :");
            mazePrim.SolveMaze(new MazeSolverFactory(WayToSolve.BFS));
            Console.WriteLine(mazePrim.SolutionToString());

            Console.ReadLine();
        }
예제 #3
0
        public MainWindow()
        {
            this.InitializeComponent();

            //Initializes communication client and factory
            MazeClient client = new MazeClient("http://localhost:3000");

            this.factory = new MazeSolverFactory(client);
        }
예제 #4
0
        static void Main(string[] args)
        {
            // TODO: Read N x N size in as an input
            var size = 15;
            var maze = new MazeModel(size);

            Console.WriteLine();
            Console.WriteLine();
            maze.GenerateMaze();
            PrintMaze(maze);

            var solver = MazeSolverFactory.CreateMazeSolver(MazeSolverType.BFS);

            var solution = solver.SolveMaze(maze);

            PrintSolution(maze, solution);
        }
예제 #5
0
 public IActionResult GetSolution(MazeViewModel model)
 {
     try
     {
         var solver           = MazeSolverFactory.CreateMazeSolver(MazeSolverType.BFS);
         var maze             = _mapper.Map <MazeModel>(model);
         var solution         = solver.SolveMaze(maze);
         var hash             = new HashSet <int>();
         int currentCellIndex = maze.MaxIndex;
         int start            = 0;
         while (currentCellIndex != 0)
         {
             hash.Add(currentCellIndex);
             currentCellIndex = solution[currentCellIndex];
         }
         hash.Add(start);
         return(Ok(hash));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
예제 #6
0
 /// <summary>
 /// Solves the maze.
 /// </summary>
 /// <param name="solver">The solver.</param>
 public override void SolveMaze(MazeSolverFactory solver)
 {
     this.solution = solver.SolveMaze(this);
 }