Exemple #1
0
        /// <summary>
        /// Generates the maze.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="rows">The rows.</param>
        /// <param name="cols">The cols.</param>
        /// <returns>maze</returns>
        public Maze GenerateMaze(string name, int rows, int cols)
        {
            Maze maze = mazeGenerator.Generate(rows, cols);

            singleplayerMazesDictionary.Add(name, maze);
            singleplayerMazesAndGamesNames.Add(name);
            return(maze);
        }
Exemple #2
0
        /// <summary>
        ///     Generates the maze.
        /// </summary>
        /// <param name="name">The maze name.</param>
        /// <param name="row">number of rows.</param>
        /// <param name="col">number of cols.</param>
        /// <returns>
        ///     maze
        /// </returns>
        public Maze GenerateMaze(string name, int row, int col)
        {
            if (_mazes.ContainsKey(name))
            {
                return(null);
            }
            Maze maze = _generator.Generate(col, row);

            maze.Name = name;
            //save the maze
            _mazes.Add(name, maze);
            return(maze);
        }
Exemple #3
0
        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        static void Main(string[] args)
        {
            //generate the maze.
            DFSMazeGenerator mazeGenerator = new DFSMazeGenerator();
            Maze             maze          = mazeGenerator.Generate(30, 30);
            //adapt the maze.
            SearchableMazeAdapter searchableMaze = new SearchableMazeAdapter(maze);

            //printing the maze.
            Console.Write(searchableMaze.MyMaze.ToString());

            Solution <Position> BFSSolution;
            Solution <Position> DFSSolution;

            //solving by BFS.
            ISearcher <Position> searcher = new BFS <Position>();

            BFSSolution      = searcher.Search(searchableMaze);
            BFSSolution.Name = searchableMaze.MyMaze.Name;
            searchableMaze.Clean();

            //solving by DFS.
            searcher         = new DFS <Position>();
            DFSSolution      = searcher.Search(searchableMaze);
            DFSSolution.Name = searchableMaze.MyMaze.Name;

            //printing the solutions.
            Console.WriteLine(BFSSolution.EvaluatedNodes);
            Console.WriteLine(DFSSolution.EvaluatedNodes);
        }
Exemple #4
0
        /// <summary>
        /// Function Compares Bfs and Dfs algorithm functions.
        /// </summary>
        public void CompareSolvers()
        {
            IMazeGenerator dfsMaze = new DFSMazeGenerator();


            // Print the maze.
            //Console.WriteLine(dfsMaze.ToString());
            StatePool <Position> spDfs = new StatePool <Position>();
            //Adapter adDfs = new Adapter(2, 2, 0, 0, 1, 1, "test Dfs", spDfs);
            Maze maze = dfsMaze.Generate(500, 500);

            Console.WriteLine(maze.ToString());
            Adapter adDfs               = new Adapter(maze, spDfs);
            ISearcher <Position> dfs    = new Dfs <Position>();
            Solution <Position>  solDfs = dfs.Search(adDfs);

            Console.WriteLine(Adapter.ToJson(solDfs, "test")); // Creates the solution in Json format.

            /*
             * StatePool<Position> spBfs = new StatePool<Position>();
             * // Adapter adBfs = new Adapter(10, 10, 0, 0, 8, 1, "test Bfs", spBfs);
             * Maze maze = dfsMaze.Generate(500, 500);
             * Console.WriteLine(maze.ToString());
             * Adapter adBfs = new Adapter(maze, spBfs);
             * ISearcher<Position> bfs = new Bfs<Position>();
             * Solution<Position> solBfs = bfs.search(adBfs);
             * //Console.WriteLine(adBfs.ToJson(solBfs));
             */
        }
Exemple #5
0
        /// <summary>
        /// Compares the solvers.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="col">The col.</param>
        public static void CompareSolvers(int row, int col)
        {
            // create maze
            DFSMazeGenerator myMazeGen = new DFSMazeGenerator();
            Maze             maze      = myMazeGen.Generate(row, col);

            Console.WriteLine(maze);
            ObjectAdapter mazeAdapter = new ObjectAdapter(maze);

            // BFS solution
            ISearcher <Position> sbfs = new BFS <Position>();

            sbfs.Search(mazeAdapter);

            // print num of stages
            Console.WriteLine("BFS: " + sbfs.GetNumberOfNodesEvaluated());

            // DFS solution
            ISearcher <Position> sdfs = new DFS <Position>();

            sdfs.Search(mazeAdapter);

            // print num of stages
            Console.WriteLine("DFS: " + sdfs.GetNumberOfNodesEvaluated());
        }
Exemple #6
0
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="name">the name of the game</param>
        /// <param name="row">num of rows</param>
        /// <param name="col">num of columns</param>
        public Game(string name, int row, int col)
        {
            DFSMazeGenerator dfs = new DFSMazeGenerator();

            myMaze      = dfs.Generate(row, col);
            myMaze.Name = name;
        }
        private static void Main(string[] args)
        {
            // the maze size 100x100
            int col = 100;
            int row = 100;

            // create maze with DFSMazeGenerator
            DFSMazeGenerator generator = new DFSMazeGenerator();
            Maze             maze      = generator.Generate(col, row);

            // print the maze
            Console.Write(maze.ToString());

            // adapt the maze and solve it with BFS
            ISearchable <Position> adapter     = new MazeAdapter(maze);
            ISearcher <Position>   bfsSearcher = new BestFirstSearch <Position>();

            bfsSearcher.Search(adapter);

            int bfsNumOfStases = bfsSearcher.GetNumberOfNodesEvaluated();

            // solve the maze with DFS
            ISearcher <Position> dfsSearcher = new DepthFirstSearch <Position>();

            dfsSearcher.Search(adapter);

            int dfsNumOfStases = dfsSearcher.GetNumberOfNodesEvaluated();

            // print the num of evalueted nodes for BFS and DFS
            Console.WriteLine("number of BFS states:" + bfsNumOfStases);
            Console.WriteLine("number of DFS states:" + dfsNumOfStases);

            Console.Read();
        }
Exemple #8
0
        /// <summary>
        /// Starts the game.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="rows">The rows.</param>
        /// <param name="cols">The cols.</param>
        /// <param name="client">The client.</param>
        /// <returns></returns>
        public bool StartGame(string name, int rows, int cols, TcpClient client)
        {
            // if the game doesn't exist
            if (MultiplayerMazeList.ContainsKey(name))
            {
                return(true);
            }
            // generate
            DFSMazeGenerator dfsMazeGenerator = new DFSMazeGenerator();
            Maze             maze             = dfsMazeGenerator.Generate(rows, cols);

            maze.Name = name;

            // add to games
            MazeGame game = new MazeGame(maze);

            MultiplayerMazeList[name] = game;

            game.AddPlayer(client, name);

            if (MultiplayerMazeList.ContainsKey(name))
            {
                MultiplayerMazeList.Remove(name);
            }

            return(false);
        }
Exemple #9
0
        /// <summary>
        /// Gets the maze.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="rows">The rows.</param>
        /// <param name="cols">The cols.</param>
        /// <returns></returns>
        public Maze GetMaze(string name, int rows, int cols)
        {
            DFSMazeGenerator generatorMaze = new DFSMazeGenerator();
            Maze             maze          = generatorMaze.Generate(rows, cols);

            maze.Name = name;
            return(maze);
        }
Exemple #10
0
        /// <summary>
        /// generates a maze with the maze adapter
        /// </summary>
        /// <param name="name"></param>
        /// <param name="rows"></param>
        /// <param name="cols"></param>
        /// <returns></returns>
        public Maze Generate(string name, int rows, int cols)
        {
            DFSMazeGenerator mazeGenerator = new DFSMazeGenerator();
            Maze             m             = mazeGenerator.Generate(rows, cols);

            m.Name = name;
            return(m);
        }
        /// <summary>
        /// Generates the specified maze.
        /// </summary>
        /// <param name="name">The name of maze.</param>
        /// <param name="rows">The rows of maze.</param>
        /// <param name="cols">The cols of maze.</param>
        /// <returns></returns>
        private Maze Generate(string name, int rows, int cols)
        {
            IMazeGenerator g    = new DFSMazeGenerator();
            Maze           maze = g.Generate(rows, cols);

            maze.Name = name;
            return(maze);
        }
Exemple #12
0
        /// <summary>
        /// generate maze
        /// </summary>
        /// <param name="name">name</param>
        /// <param name="rows">rows</param>
        /// <param name="cols">cols</param>
        /// <returns></returns>
        public Maze generateMaze(string name, int rows, int cols)
        {
            DFSMazeGenerator mazeCreator = new DFSMazeGenerator();
            Maze             maze        = mazeCreator.Generate(rows, cols);

            maze.Name = name;
            poolMaze.Add(maze.Name, maze);
            return(maze);
        }
Exemple #13
0
        /// <summary>
        /// Generates the specified name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="rows">The rows.</param>
        /// <param name="cols">The cols.</param>
        /// <returns>Maze.</returns>
        public Maze generate(string name, int rows, int cols)
        {
            var dfsMazeGenerator = new DFSMazeGenerator();
            var MyMaze           = dfsMazeGenerator.Generate(rows, cols);

            MyMaze.Name             = name;
            DictionaryOfMazes[name] = MyMaze;
            return(MyMaze);
        }
Exemple #14
0
        public Maze GenerateMaze(string name, int rows, int cols)
        {
            MazeGeneratorLib.IMazeGenerator generator = new DFSMazeGenerator();
            Maze maze = generator.Generate(rows, cols);

            maze.Name = name;
            mazes.Add(name, maze);
            return(maze);
        }
Exemple #15
0
        /// <summary>
        /// Generates a maze with a name that is given, size according the parameters
        /// </summary>
        /// <param name="name">The name of the maze.</param>
        /// <param name="rows">num of rows.</param>
        /// <param name="cols">num of cols.</param>
        /// <returns>
        /// a new maze
        /// </returns>
        public Maze generate(string name, int rows, int cols)
        {
            DFSMazeGenerator maze        = new DFSMazeGenerator();
            Maze             currentMaze = maze.Generate(rows, cols);

            currentMaze.Name = name; //this is the way?
            allMazes.Add(name, currentMaze);
            return(currentMaze);
        }
Exemple #16
0
        public Maze GenerateMaze(string name, int rows, int cols)
        {
            DFSMazeGenerator mazeGen = new DFSMazeGenerator();
            Maze             maze    = mazeGen.Generate(rows, cols);

            maze.Name = name;
            mazes.Add(name, new Pair <Maze, Solution>(maze, null));
            return(maze);
        }
Exemple #17
0
        /// <summary>
        /// Main class.
        /// Generates a Maze.
        /// Sends it CompareSolvers to compare two solvers and draw it.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            var  generator = new DFSMazeGenerator();
            Maze maze      = generator.Generate(30, 30);

            CompareSolvers(maze);

            Console.Read();
        }
Exemple #18
0
        /// <summary>
        /// Generates the maze.
        /// </summary>
        /// <param name="name">The maze's name.</param>
        /// <param name="rows">The number of rows.</param>
        /// <param name="cols">The number of cols.</param>
        /// <returns></returns>
        public Maze GenerateMaze(string name, int rows, int cols)
        {
            // create maze
            DFSMazeGenerator myMazeGen = new DFSMazeGenerator();
            Maze             myMaze    = myMazeGen.Generate(rows, cols);

            myMaze.Name = name;
            mazes.Add(name, myMaze);
            return(this.mazes[name]);
        }
Exemple #19
0
        /*
         * The generate command creates a single player maze, which is added to the database
         * and then returned to the user
         */
        public SearchableMaze GenerateMaze(string name, int rows, int cols)
        {
            Maze           m    = mazeMaker.Generate(rows, cols);
            SearchableMaze maze = new SearchableMaze(m, name);

            // The maze is saved in the database
            if (!singlePlayerMazes.ContainsKey(name))
            {
                singlePlayerMazes.Add(name, maze);
            }
            else
            {
                singlePlayerMazes[name] = maze;
                if (singlePlayerSolutions.ContainsKey(name))
                {
                    singlePlayerSolutions.Remove(name);
                }
            }
            return(maze);
        }
Exemple #20
0
 public Maze GenerateMaze(string name, int rows, int cols)
 {
     if (!mazes.ContainsKey(name))
     {
         DFSMazeGenerator mazeGenerator = new DFSMazeGenerator();
         Maze             maze          = mazeGenerator.Generate(rows, cols);
         maze.Name = name;
         mazes.Add(name, maze);
         return(maze);
     }
     return(null);
 }
Exemple #21
0
        /// <summary>
        /// Generates the maze.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="rows">The rows.</param>
        /// <param name="cols">The cols.</param>
        /// <returns></returns>
        public Maze GenerateMaze(string name, int rows, int cols)
        {
            IMazeGenerator mazeGenerator = new DFSMazeGenerator();

            Maze maze = mazeGenerator.Generate(rows, cols);

            maze.Name = name;
            cash.AddSingleGame(name, new SingleGame(name, maze, null));

            //cash.AddMaze(name, maze);
            return(maze);
        }
        public Maze GenerateMaze(string name, int rows, int cols)
        {
            IMazeGenerator mg = new DFSMazeGenerator();
            Maze           m  = mg.Generate(rows, cols);

            m.Name = name;
            if (mazeCache.ContainsKey(name))
            {
                return(null);
            }
            mazeCache.Add(m.Name, m);
            return(m);
        }
Exemple #23
0
        /// <summary>
        /// Generates the maze.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="rows">The rows.</param>
        /// <param name="cols">The cols.</param>
        /// <returns>Maze</returns>
        public Maze GenerateMaze(string name, int rows, int cols)
        {
            modelData.mutexMazes.WaitOne();
            IMazeGenerator newMaze = new DFSMazeGenerator();
            Maze           maze    = null;

            // Generate the maze.
            maze = newMaze.Generate(rows, cols);
            modelData.Mazes.Add(name, maze);
            // Unlock.
            modelData.mutexMazes.ReleaseMutex();
            return(maze);
        }
Exemple #24
0
        static void Main(string[] args)
        {
            Program        pg      = new Program();
            IMazeGenerator dfsMaze = new DFSMazeGenerator();
            Maze           maze    = dfsMaze.Generate(100, 100);
            //pg.CompareSolvers();

            // Example of Usage:

            // The following gets 2 rows, 2 coloms and 0 (Bfs algorithm), Runs the bfs algorithm
            // and returns the solution to the algorithm.
            Solution <Position> pos = pg.Solve(maze, 0);
        }
Exemple #25
0
        /// <summary>
        /// Starts the maze.
        /// </summary>
        /// <param name="name">The maze's name.</param>
        /// <param name="rows">The rows.</param>
        /// <param name="cols">The cols.</param>
        /// <param name="client">The client's connection.</param>
        public void StartMaze(string name, int rows, int cols, TcpClient client)
        {
            // create maze
            DFSMazeGenerator myMazeGen = new DFSMazeGenerator();
            Maze             myMaze    = myMazeGen.Generate(rows, cols);

            myMaze.Name = name;

            // create game
            Game myGame = new Game(myMaze, client);

            this.games.Add(name, myGame);
        }
Exemple #26
0
        static void Main(string[] args)
        {
            DFSMazeGenerator mazeGenerator = new DFSMazeGenerator();
            Maze             maze          = mazeGenerator.Generate(5, 5);

            Console.WriteLine(maze.ToString());

            SearchableMaze searchableMaze = new SearchableMaze(maze);
            BFS <Position> bfsSolver      = new BFS <Position>();
            DFS <Position> dfsSolver      = new DFS <Position>();

            Console.WriteLine("BFS:");
            Console.WriteLine(bfsSolver.search(searchableMaze));
            Console.WriteLine(bfsSolver.getNumberOfNodesEvaluated());

            Console.WriteLine("DFS:");
            Console.WriteLine(dfsSolver.search(searchableMaze));
            Console.WriteLine(dfsSolver.getNumberOfNodesEvaluated());

            //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());
            //SearchableMaze searchableMaze = new SearchableMaze(maze);
            //BFS<Position> bfsSolver = new BFS<Position>();
            //DFS<Position> dfsSolver = new DFS<Position>();
            //Console.WriteLine("BFS:");
            //Console.WriteLine(bfsSolver.search(searchableMaze));
            //Console.WriteLine(bfsSolver.getNumberOfNodesEvaluated());

            //Console.WriteLine("DFS:");
            //Console.WriteLine(dfsSolver.search(searchableMaze));
            //Console.WriteLine(dfsSolver.getNumberOfNodesEvaluated());



            Console.Read();
        }
Exemple #27
0
        /// <summary>
        /// Starts the game.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="rows">The rows.</param>
        /// <param name="cols">The cols.</param>
        /// <param name="gamer">The gamer.</param>
        /// <returns></returns>
        public Maze StartGame(string name, int rows, int cols, string player /*, ClientNotifier gamer*/)
        {
            //Maze maze = GenerateMaze(name, rows, cols);
            IMazeGenerator mazeGenerator = new DFSMazeGenerator();
            Maze           maze          = mazeGenerator.Generate(rows, cols);

            maze.Name = name;
            MultiGame game = new MultiGame(name, maze, player);

            //game.AddGamer(gamer);
            //cash.AddGame(name, game);
            cash.AddMultiGame(name, game);
            return(maze);
        }
Exemple #28
0
        /// <summary>
        /// Compare the solvers we created by using the adapter desing pattern between
        /// the maze and searchable.
        /// </summary>
        static void CompareSolvers()
        {
            DFSMazeGenerator       dfsMaze = new DFSMazeGenerator();
            Maze                   maze    = dfsMaze.Generate(100, 100);
            ISearchable <Position> adapt   = new MazeToSearchableAdapter(maze);
            BFSSearcher <Position> bfs     = new BFSSearcher <Position>();
            DFSSearcher <Position> dfs     = new DFSSearcher <Position>();

            //Console.WriteLine(maze);
            bfs.Search(adapt);
            Console.WriteLine("Best First Search evaluated {0} nodes.", bfs.GetNumberOfNodesEvaluated());
            dfs.Search(adapt);
            Console.WriteLine("DFS evaluated {0} nodes.", dfs.GetNumberOfNodesEvaluated());
        }
Exemple #29
0
        public Maze GenerateMaze(string nameOfGame, int rows, int cols)
        {
            if (SPGames.ContainsKey(nameOfGame))
            {
                // The game is already exist in the system.
                throw new Exception($"The game '{nameOfGame}' already exists");
            }
            // Generate a maze with the given size.
            IMazeGenerator mazeGenerator = new DFSMazeGenerator();
            Maze           maze          = mazeGenerator.Generate(rows, cols);

            maze.Name = nameOfGame;
            SPGames.Add(nameOfGame, new SinglePlayerGame(maze));
            return(maze);
        }
Exemple #30
0
        public static void CompareSolvers()
        {
            DFSMazeGenerator generator = new DFSMazeGenerator();
            Maze             m         = generator.Generate(5, 6);

            Console.WriteLine(m.ToString());

            BestFirstSearch <CellType> bfs = new BestFirstSearch <CellType>();
            DFS <CellType>             dfs = new DFS <CellType>();

            Solution <CellType> SolBFS = bfs.search(m);
            Solution <CellType> SolDFS = dfs.search(m);

            Console.ReadLine();
        }