public void KnockWall_removes_east_wall_if_neighbour_is_east() { var current = new Cell(0, 0); var neighbour = new Cell(1, 0); var maze = new Maze(5, 5); maze.TestKnockWall(current, neighbour); Assert.IsFalse(current.AreAllWallsIntact, "Current has still all walls intact."); Assert.IsFalse(neighbour.AreAllWallsIntact, "Neighbour has still all walls intact."); Assert.IsFalse(current.HasEastWall, "Current still has east wall."); Assert.IsFalse(neighbour.HasWestWall, "Neighbour still has west wall."); }
public Maze(int width, int height) { Width = width; Height = height; VisitedCells = 0; Cells = new Cell[width, height]; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { Cells[x, y] = new Cell(x, y); } } }
private void KnockWall(Cell current, Cell neighbour) { // TODO: Which wall leads to the neighbour? // Poor man's solution // Neighbour is South if (current.X == neighbour.X && current.Y < neighbour.Y) { current.Wall[(int) Direction.South] = false; neighbour.Wall[(int) Direction.North] = false; return; } // Neighbour is North if (current.X == neighbour.X && current.Y > neighbour.Y) { current.Wall[(int) Direction.North] = false; neighbour.Wall[(int) Direction.South] = false; return; } // Neighbour is East if (current.Y == neighbour.Y && current.X < neighbour.X) { current.Wall[(int) Direction.East] = false; neighbour.Wall[(int) Direction.West] = false; return; } // Neighbour is West current.Wall[(int) Direction.West] = false; neighbour.Wall[(int) Direction.East] = false; }
private List<Cell> GetNeighbours(Cell cell) { var neighbours = new List<Cell>(); // North var northX = cell.X; var northY = cell.Y + 1; if (northY < Height) { var northCell = Cells[northX, northY]; if (!northCell.IsVisited) { neighbours.Add(northCell); } } // East var eastX = cell.X + 1; var eastY = cell.Y; if (eastX < Width) { var eastCell = Cells[eastX, eastY]; if (!eastCell.IsVisited) { neighbours.Add(eastCell); } } // South var southX = cell.X; var southY = cell.Y - 1; if (southY >= 0) { var southCell = Cells[southX, southY]; if (!southCell.IsVisited) { neighbours.Add(southCell); } } // West var westX = cell.X - 1; var westY = cell.Y; if (westX >= 0) { var westCell = Cells[westX, westY]; if (!westCell.IsVisited) { neighbours.Add(westCell); } } return neighbours; }
public void TestKnockWall(Cell current, Cell neighbour) { KnockWall(current, neighbour); }
public List<Cell> TestGetNeighbours(Cell cell) { return GetNeighbours(cell); }
public void IsStart_returns_false_for_new_Cell() { var cell = new Cell(0,0); Assert.IsFalse(cell.IsStart); }
public void AreAllWallsIntakt_returns_true_for_new_Cell() { var cell = new Cell(0,0); Assert.IsTrue(cell.AreAllWallsIntact); }
public void KnockWall_removes_north_wall_if_neighbour_is_north() { var current = new Cell(0, 1); var neighbour = new Cell(0, 0); var maze = new Maze(5, 5); maze.TestKnockWall(current, neighbour); Assert.IsFalse(current.AreAllWallsIntact, "Current has still all walls intact."); Assert.IsFalse(neighbour.AreAllWallsIntact, "Neighbour has still all walls intact."); Assert.IsFalse(current.HasNorthWall, "Current still has north wall."); Assert.IsFalse(neighbour.HasSouthWall, "Neighbour still has south wall."); }