private void TryVisitCell(AbstractDataStructures.Queue <Cell> visitedCells, string[,] matrix, Cell cell)
 {
     if (this.IsCellAccessible(matrix, cell))
     {
         visitedCells.Enqueue(cell);
         matrix[cell.X, cell.Y] = cell.Value.ToString();
     }
 }
        public static IEnumerable<int> CalculateNextMembers(int startupNumber, int count)
        {
            var sequence = new AbstractDataStructures.Queue<int>(); // My implementation of Queue
            sequence.Enqueue(startupNumber);

            var result = new List<int>();
            result.Add(startupNumber);

            for (int i = 0; i < count; i++)
            {
                var firstMember = sequence.Dequeue();

                foreach (var operation in operations)
                {
                    var nextMember = operation(firstMember);
                    sequence.Enqueue(nextMember);
                    result.Add(nextMember);
                }
            }

            return result;
        }
        public string[,] FindAllPaths(string[,] matrix)
        {
            var startupCell = this.GetStartupCell(matrix);

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

            while (visitedCells.Count > 0)
            {
                var currentCell = visitedCells.Dequeue();
                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;
        }
        public string[,] FindAllPaths(string[,] matrix)
        {
            var startupCell = this.GetStartupCell(matrix);

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

            visitedCells.Enqueue(startupCell);

            while (visitedCells.Count > 0)
            {
                var currentCell = visitedCells.Dequeue();
                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);
        }
Example #5
0
        public static IEnumerable <int> CalculateNextMembers(int startupNumber, int count)
        {
            var sequence = new AbstractDataStructures.Queue <int>(); // My implementation of Queue

            sequence.Enqueue(startupNumber);

            var result = new List <int>();

            result.Add(startupNumber);

            for (int i = 0; i < count; i++)
            {
                var firstMember = sequence.Dequeue();

                foreach (var operation in operations)
                {
                    var nextMember = operation(firstMember);
                    sequence.Enqueue(nextMember);
                    result.Add(nextMember);
                }
            }

            return(result);
        }