private void ParseMazeFile(string mazeFilePath) { StreamReader sr = new StreamReader(mazeFilePath); int x = 0; int y = 0; string line = string.Empty; while ((line = sr.ReadLine()) != null) { foreach (char c in line) { Debug.Write(c); MazeTile mt = new MazeTile(x, y, Maze.ParseTile("wall", c)); if (Maze.ParseTile("start", c)) { Start = mt; } if (Maze.ParseTile("finish", c)) { Finish = mt; } Layout.Add(mt); x++; } y++; x = 0; Debug.Write("\n"); } }
public MazeTile GetTile(int X, int Y) { MazeTile mt = new MazeTile(); mt = Layout.Single(t => t.X == X && t.Y == Y); return(mt); }
/// <summary> /// Move to an ajacent tile following this priority: /// - You have no other option /// - You have visited it less than another option /// - It is closer to the exit than an equally visited option /// - Randomly /// </summary> /// <param name="theMaze"></param> /// <returns></returns> private MazeTile ChooseNextLocation(Maze theMaze) { var nextTile = new MazeTile(); var choices = this.LookAround(theMaze); choices.RemoveAll(c => c.isWall); //Stuck - return an invalid tile to kill the maze. if (choices.Count == 0) { return(nextTile); } //Dead End - kill this tile if (choices.Count == 1) { CurrentTile.isWall = true; return(choices[0]); } FilterByLeastVisited(choices); FilterByLeastDistance(choices); nextTile = ChooseRandom(choices); return(nextTile); }
public bool Solve(Maze theMaze) { InitVisitedList(theMaze); this.CurrentTile = theMaze.Start; this._Exit = IKnowExitCoordinates ? theMaze.Finish : null; this.Move(theMaze); return true; }
public bool Solve(Maze theMaze) { InitVisitedList(theMaze); this.CurrentTile = theMaze.Start; this._Exit = IKnowExitCoordinates ? theMaze.Finish : null; this.Move(theMaze); return(true); }
private bool MoveToNextLocation(MazeTile Next) { if (!Next.isValid) { return(false); } PreviousTile = CurrentTile; CurrentTile = Next; _Visited[CurrentTile]++; return(true); }
public Maze(string mazeFilePath) { Layout = new List <MazeTile>(); Start = new MazeTile(); Finish = new MazeTile(); ParseMazeFile(mazeFilePath); if (!this.Start.isValid || !this.Finish.isValid) { throw new Exception("Maze must contain a Start and Finish tile."); } }
public Maze(string mazeFilePath) { Layout = new List<MazeTile>(); Start = new MazeTile(); Finish = new MazeTile(); ParseMazeFile(mazeFilePath); if (!this.Start.isValid || !this.Finish.isValid ) { throw new Exception("Maze must contain a Start and Finish tile."); } }
private void Move(Maze theMaze) { //From Current Location MazeTile Next = this.ChooseNextLocation(theMaze); if (!this.MoveToNextLocation(Next)) { throw new Exception("No path exists between start and finish."); } if (Moved != null) { Moved(this, new EventArgs()); } if (!CurrentTile.Equals(theMaze.Finish)) { this.Move(theMaze); } }
/// <summary> /// Move to an ajacent tile following this priority: /// - You have no other option /// - You have visited it less than another option /// - It is closer to the exit than an equally visited option /// - Randomly /// </summary> /// <param name="theMaze"></param> /// <returns></returns> private MazeTile ChooseNextLocation(Maze theMaze) { var nextTile = new MazeTile(); var choices = this.LookAround(theMaze); choices.RemoveAll(c => c.isWall); //Stuck - return an invalid tile to kill the maze. if (choices.Count == 0) { return nextTile; } //Dead End - kill this tile if (choices.Count == 1) { CurrentTile.isWall = true; return choices[0]; } FilterByLeastVisited(choices); FilterByLeastDistance(choices); nextTile = ChooseRandom(choices); return nextTile; }
private bool MoveToNextLocation(MazeTile Next) { if (!Next.isValid) { return false; } PreviousTile = CurrentTile; CurrentTile = Next; _Visited[CurrentTile]++; return true; }
public MazeTile GetTile(int X, int Y) { MazeTile mt = new MazeTile(); mt = Layout.Single(t => t.X == X && t.Y == Y); return mt; }