public MazeSolver(MazeState mazeState) { if (mazeState == null) { throw new ArgumentNullException("mazeState"); } if (mazeState.Width * mazeState.Height == 0) { throw new ArgumentException("Width and height of the maze cannot be zero!"); } Width = mazeState.Width; Height = mazeState.Height; InitalizeMazeCells(mazeState); }
private void InitalizeMazeCells(MazeState mazeState) { Cells = new Cell[Width * Height]; for (int i = 0; i < Width * Height; i++) { Cells[i] = new Cell(); if (mazeState.Data[i].Any(w => w == "north")) { Cells[i].Sides[CellSide.North] = CellSideState.Sealed; } if (mazeState.Data[i].Any(w => w == "west")) { Cells[i].Sides[CellSide.West] = CellSideState.Sealed; } if (i < Width * Height - 1) { if (mazeState.Data[i + 1].Any(w => w == "west")) { Cells[i].Sides[CellSide.East] = CellSideState.Sealed; } } else { Cells[i].Sides[CellSide.East] = CellSideState.Sealed; } if (i < Width * (Height - 1)) { if (mazeState.Data[i + Width].Any(w => w == "north")) { Cells[i].Sides[CellSide.South] = CellSideState.Sealed; } } else { Cells[i].Sides[CellSide.South] = CellSideState.Sealed; } } }