Ejemplo n.º 1
0
 private void TryVisitCell(AbstractDataStructures.Stack <Cell> visitedCells, string[,] matrix, Cell cell)
 {
     if (this.IsCellAccessible(matrix, cell))
     {
         visitedCells.Push(cell);
         matrix[cell.X, cell.Y] = cell.Value.ToString();
     }
 }
Ejemplo n.º 2
0
        public string[,] FindAllPaths(string[,] matrix)
        {
            var startupCell = this.GetStartupCell(matrix);

            var visitedCells = new AbstractDataStructures.Stack<Cell>(); // My implementation of Stack
            visitedCells.Push(startupCell);

            while (visitedCells.Count > 0)
            {
                var currentCell = visitedCells.Pop();
                int x = currentCell.X, y = currentCell.Y, nextValue = currentCell.Value + 1;

                this.TryVisitCell(visitedCells, matrix, new Cell(x, y + 1, nextValue));
                this.TryVisitCell(visitedCells, matrix, new Cell(x, y - 1, nextValue));
                this.TryVisitCell(visitedCells, matrix, new Cell(x + 1, y, nextValue));
                this.TryVisitCell(visitedCells, matrix, new Cell(x - 1, y, nextValue));
            }

            this.MarkInaccessibleCells(matrix);

            return matrix;
        }
Ejemplo n.º 3
0
        public string[,] FindAllPaths(string[,] matrix)
        {
            var startupCell = this.GetStartupCell(matrix);

            var visitedCells = new AbstractDataStructures.Stack <Cell>(); // My implementation of Stack

            visitedCells.Push(startupCell);

            while (visitedCells.Count > 0)
            {
                var currentCell = visitedCells.Pop();
                int x = currentCell.X, y = currentCell.Y, nextValue = currentCell.Value + 1;

                this.TryVisitCell(visitedCells, matrix, new Cell(x, y + 1, nextValue));
                this.TryVisitCell(visitedCells, matrix, new Cell(x, y - 1, nextValue));
                this.TryVisitCell(visitedCells, matrix, new Cell(x + 1, y, nextValue));
                this.TryVisitCell(visitedCells, matrix, new Cell(x - 1, y, nextValue));
            }

            this.MarkInaccessibleCells(matrix);

            return(matrix);
        }