Ejemplo n.º 1
0
        public void BreathFirstSearch(Cell startingPoint)
        {
            Queue<Tuple<Cell, int>> queue = new Queue<Tuple<Cell, int>>();
            queue.Enqueue(new Tuple<Cell, int>(startingPoint, 1));
            while (queue.Count > 0)
            {
                Tuple<Cell, int> currentElement = queue.Dequeue();

                for (int i = 0; i < this.directions.GetLength(0); i++)
                {
                    int newRow = currentElement.Item1.Row + this.directions[i, 0];
                    int newCol = currentElement.Item1.Col + this.directions[i, 1];

                    if (CheckIfPassable(newRow, newCol))
                    {
                        Cell child = new Cell();
                        child.Row = newRow;
                        child.Col = newCol;

                        this.labyrinth[child.Row, child.Col] = currentElement.Item2.ToString();
                        queue.Enqueue(new Tuple<Cell, int>(child, currentElement.Item2 + 1));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public Cell GetStartingPoint()
        {
            int rows = this.labyrinth.GetLength(0);
            int cols = this.labyrinth.GetLength(1);
            Cell startingPoint = new Cell();

            for (int row = 0; row < rows; row++)
            {
                for (int col = 0; col < cols; col++)
                {
                    if (this.labyrinth[row, col] == "*")
                    {
                        startingPoint.Row = row;
                        startingPoint.Col = col;
                        return startingPoint;
                    }
                }
            }

            return startingPoint;
        }