/// <summary> /// This method will create the maze using the DFS /// algorithm /// </summary> /// <param name="createable">A creatable maze</param> public void create(ICreateable <T> createable) { this.maze = createable.GetMaze(); this.HEIGHT = createable.GetHeight(); this.WIDTH = createable.GetWidth(); RandomStart(); }
/// <summary> /// Main Method that will created a maze using Prims Algorithm </summary> /// <param name="createable">Maze</param> public void create(ICreateable <T> createable) { this.maze = createable.GetMaze(); this.height = createable.GetHeight(); this.width = createable.GetWidth(); List <Node <T> > primList = new List <Node <T> >(); rand = new Random(); //Sets a random Starting Point int rRow = rand.Next(height); int rCol = rand.Next(width); maze.GetNode(rRow, rCol).SetValue(0); maze.SetStartPoints(rRow, rCol); //Adds Node to the Prims List primList.Add(maze.GetNode(rRow, rCol)); //Will run as long as the List is not empty while (primList.Count > 0) { primList = primList.Distinct().ToList(); this.getNeighbors(primList); } //Sets the end Point of the maze this.maze.SetEndPoints(last.GetRow(), last.GetCol()); }
/// <summary> /// Constructor method that gets a maze and the name of the Game</summary> /// <param name="m">The new game Maze</param> /// <param name="name">The Name of the Game</param> public Game(GeneralMaze <int> m, string name) { this.mazePlayer1 = m; this.mazeList = new List <GeneralMaze <int> >(); this.playersList = new List <Player>(); this.GameName = name; this.mazeList.Add(m); }
public void startProgram() { _2DMaze <int> maze = new _2DMaze <int>(5, 5); GeneralMaze <int> Cm = new GeneralMaze <int>(maze); Cm.Generate("mazushshsh", 1); Cm.Solve(0); maze.Print(); }
public Solution <T> Search(ISearchable <T> searchable) { this.closedList = new Solution <T>(new List <Node <T> >()); this.openList = new Solution <T>(new List <Node <T> >()); this.maze = searchable.GetMaze(); // Searcher's abstract method overriding addToOpenList(maze.GetStartPoint()); // HashSet<State<T>> closed = new HashSet<State<T>>(); while (this.openList.GetLength() != 0) { // inherited from Searcher, removes the best state Node <T> bestState = popOpenList(); this.closedList.AddSolution(bestState); if (bestState.Equals(maze.GetEndPoint())) { return(backTrace(searchable)); // private method, back traces through the parents } // calling the delegated method, returns a list of states with n as a parent List <Node <T> > succerssors = searchable.getAllPossibleStates(bestState); foreach (Node <T> s in succerssors) { // If it is not in CLOSED and it is not in OPEN: //evaluate it, add it to OPEN, and record its parent. if (!this.closedList.Containe(s) && !this.openList.Containe(s)) { s.SetCost(s.GetCost() + bestState.GetCost()); addToOpenList(s); s.SetParent(bestState); } else { //Otherwise, if this new path is better than previous one, change its recorded parent. if ((s.GetCost() + bestState.GetCost()) < this.closedList.GetCost(s)) { s.SetParent(bestState); //i. If it is not in OPEN add it to OPEN. if (!this.openList.Containe(s)) { addToOpenList(s); } // ii.Otherwise, adjust its priority in OPEN using this new evaluation. else { this.openList.FindNode(s).SetCost(s.GetCost() + bestState.GetCost()); } } } } } return(backTrace(searchable)); }
/// <summary> /// Creates a second maze for the Second player /// that has joined the game </summary> public void CreateSecondMaze() { Node <int>[,] grid = mazePlayer1.GetGrid(); Node <int> start = mazePlayer1.GetStartPoint(); Node <int> end = mazePlayer1.GetEndPoint(); _2DMaze <int> twoDMaze = new _2DMaze <int>(); twoDMaze.height = mazePlayer1.GetHeight(); twoDMaze.width = mazePlayer1.GetWidth(); twoDMaze.CopyGrid(grid); //Switches around the starting and ending cell in the Second Maze twoDMaze.SetStartingCell(end.GetRow(), end.GetCol()); twoDMaze.SetEndingCell(start.GetRow(), start.GetCol()); this.mazePlayer2 = new GeneralMaze <int>(twoDMaze); this.mazePlayer2.MakeMazeString(); this.mazePlayer2.UpdateMembers(); this.mazePlayer2.Name = this.mazePlayer1.Name + "_2"; }
/// <summary> /// Sets the maze for the current Player</summary> /// <param name="m">maze to be set</param> public void SetPlayerMaze(GeneralMaze <int> m) { this.playerMaze = m; this.currentNode = playerMaze.GetStartPoint(); }
/// <summary> /// Sets the maze for the second player </summary> /// <param name="maze">MAze to be set</param> public void SetMazePlayer2(GeneralMaze <int> maze) { this.mazePlayer2 = maze; }