Esempio n. 1
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));
             */
        }
Esempio n. 2
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());
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            ISearcher <Position> bfs       = new BestFirstSearcher <Position>();
            ISearcher <Position> dfs       = new DepthFirstSearcher <Position>();
            DFSMazeGenerator     mazeMaker = new DFSMazeGenerator();
            MazeWrap             m         = new MazeWrap();

            Console.WriteLine("Start {0} - End {1}", m.InitialPos.ToString(), m.GoalPos.ToString());
            Console.WriteLine("Rows {0} - Cols {1}", m.Rows, m.Cols);
            SearchableMaze maze = new SearchableMaze(m);
            Maze           k;

            maze.print();
            if (bfs.search(maze) != null)
            {
                Console.WriteLine("Number of BFS evaluations: {0}", bfs.getNumberOfEvaluations());
            }
            else
            {
                Console.WriteLine("No solution found!");
            }

            if (dfs.search(maze) != null)
            {
                Console.WriteLine("Number of DFS evaluations: {0}", dfs.getNumberOfEvaluations());
            }
            else
            {
                Console.WriteLine("No solution found!");
            }
        }
Esempio n. 5
0
    public static void GenerateMazeHelper(int size, int[] sections, int loops, int floors, Difficulty difficulty, int seed)
    {
        System.Random msgRand = new System.Random(seed);
        MazeNode[,] roots = new MazeNode[5, 8];
        for (int i = 0; i < floors; i++)
        {
            int             section = 0;
            MazeNode        root    = DFSMazeGenerator.GenerateMaze(seed, size, size, i);
            List <MazeNode> sectionroots;

            sectionroots = GenerateSections(root, sections[i], size, size);

            foreach (MazeNode r in sectionroots)
            {
                roots[i, section] = r;
                foreach (MazeNode n in nodesInSection(r))
                {
                    n.sectionNumber = section;
                }
                r.isRoot = true;
                GenerateLoops(r, loops, size);
                GenerateLadders(i, section, r, floors, sections[i]);
                GenerateMessages(r, msgRand);
                ActorGenerator.GenerateActorsHelper(difficulty, r, seed);
                SetIntersectionNodes(r);
                section++;
                seed++;
            }
        }
        DifferentSections = roots;
        connectLadderNodes(difficulty, roots);
    }
Esempio n. 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;
        }
Esempio n. 7
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);
        }
        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();
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
 public Model()
 {
     this.mazeGenerator          = new DFSMazeGenerator();
     this.algorithmFactory       = new SearchAlgorithmFactory <Position>();
     this.singlePlayerMazes      = new Dictionary <string, Maze>();
     this.multiPlayerMazes       = new Dictionary <string, Maze>();
     this.joinableMazes          = new Dictionary <string, Maze>();
     this.activeMultiPlayerMazes = new Dictionary <string, Maze>();
 }
Esempio n. 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);
        }
Esempio n. 15
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);
        }
Esempio n. 16
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();
        }
Esempio n. 17
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);
        }
Esempio n. 18
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);
        }
Esempio n. 19
0
        /*
         * The Model constructor.
         * The method constructs a new Model object,
         * and sets the data structures of the program.
         */
        public Model()
        {
            // Databases
            this.games   = new Dictionary <string, Game>();
            this.players = new Dictionary <Player[], string>();

            // Maze generator
            this.mazer = new DFSMazeGenerator();
        }
Esempio n. 20
0
 /// <summary>
 /// The constructor generates the required objects
 /// </summary>
 public MazeGameModel()
 {
     mazeMaker             = new DFSMazeGenerator();
     singlePlayerMazes     = new Dictionary <string, SearchableMaze>();
     singlePlayerSolutions = new Dictionary <string, Solution <Position> >();
     multiplayerMazes      = new Dictionary <string, MultiplayerMazeGame>();
     playerToGameMap       = new Dictionary <string, MultiplayerMazeGame>();
     bfs = new BestFirstSearcher <Position>();
     dfs = new DepthFirstSearcher <Position>();
 }
Esempio n. 21
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]);
        }
Esempio n. 22
0
 public MazeModel()
 {
     _mazes         = new Dictionary <string, Maze>();
     _games         = new Dictionary <string, GameController>();
     _solutions     = new Dictionary <string, MazeSolution>();
     _generator     = new DFSMazeGenerator();
     _algorithms    = new ISearcher <Position> [2];
     _algorithms[0] = new BestFirstSearch <Position>();
     _algorithms[1] = new DepthFirstSearch <Position>();
 }
Esempio n. 23
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);
 }
Esempio n. 24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Model"/> class.
 /// </summary>
 /// <param name="icontroller">The icontroller.</param>
 public Model(IController icontroller)
 {
     this.icontroller            = icontroller;
     this.mazeGenerator          = new DFSMazeGenerator();
     this.algorithmFactory       = new SearchAlgorithmFactory <Position>();
     this.singlePlayerMazes      = new Dictionary <string, Maze>();
     this.mazeSolutions          = new Dictionary <string, Solution <Position> >();
     this.multiPlayerMazes       = new Dictionary <string, Maze>();
     this.joinableMazes          = new Dictionary <string, MazeGame>();
     this.activeMultiPlayerMazes = new Dictionary <string, MazeGame>();
     this.playersAndGames        = new Dictionary <Player, MazeGame>();
 }
Esempio n. 25
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);
        }
Esempio n. 26
0
        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);
        }
Esempio n. 27
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);
        }
Esempio n. 28
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);
        }
Esempio n. 29
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);
        }
Esempio n. 30
0
File: Program.cs Progetto: galh8/ex1
        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();
        }