/// <summary>
        /// Initializes two dimensional array of PrimCell objects,
        /// by given dimensions.
        /// </summary>
        /// <param name="rows">Maze width, as number of rows.</param>
        /// <param name="columns">Maze height as number of columns.</param>
        /// <returns>Maze as two dimensional array of IMazeCell objects.</returns>
        private IMazeCell[,] InitializePrimMaze(int rows, int columns)
        {
            var maze = new PrimCell[rows, columns];

            for (int row = 0; row < rows; row++)
            {
                for (int col = 0; col < columns; col++)
                {
                    maze[row, col] = new PrimCell(row, col);
                }
            }

            return(maze);
        }
Esempio n. 2
0
    public void AlgorithmStart()
    {
        // 시작 PrimCell 정의 및 Pmaze 시작부 초기화
        PrimCell start = new PrimCell(0, 0, null);

        Pmaze.At(start.Row, start.Col) = 'S';

        // 시작 PrimCell의 이웃 PrimCell 정의 및 리스트에 추가
        List <PrimCell> _frontier = new List <PrimCell>();

        _frontier.Add(new PrimCell(1, 0, start));
        _frontier.Add(new PrimCell(0, 1, start));

        PrimCell _child, _gc;

        while (_frontier.Count > 0)
        {
            // 리스트 내 랜덤 좌표를 자식으로 정의 및 _frontier 리스트에서 제거
            int rand_p = Random.Range(0, _frontier.Count);
            _child = _frontier[rand_p];
            _frontier.RemoveAt(rand_p);

            // 선택된 자식의 자식 PrimCell을 가져와 좌표를 _r, _c 변수로 정의
            _gc = _child.GetChild();
            int _r = _gc.Row;
            int _c = _gc.Col;

            // 선택된 자식 PrimCell의 좌표가 벽인지, 방문한 적 없을 경우
            if (Pmaze.IsMoveable(_r, _c))
            {
                Pmaze.At(_child.Row, _child.Col) = ' ';
                Pmaze.At(_r, _c) = 'E';

                List <PrimCell> _neighbors = Pmaze.GetNeighbors(_gc, true);
                foreach (PrimCell _cell in _neighbors)
                {
                    _frontier.Add(_cell);
                }

                Pmaze.At(_r, _c) = ' ';
            }
        }

        Pmaze.At(Pmaze.Rows - 1, Pmaze.Cols - 1) = 'E';
    }
Esempio n. 3
0
 public void CheckIfNegativePrimcellCoordinatesThrowException()
 {
     PrimCell primcell = new PrimCell(-2, -5);
 }
Esempio n. 4
0
 public PrimCell(int _row, int _col, PrimCell _parent)
 {
     this.row    = _row;
     this.col    = _col;
     this.Parent = _parent;
 }
Esempio n. 5
0
    public override bool Equals(object obj)
    {
        PrimCell _obj = (PrimCell)obj;

        return(Row.Equals(_obj.Row) && Col.Equals(_obj.Col));
    }
        public void MatrixCoordinatesThrowExcepion()
        {
            PrimCell cell = new PrimCell(0, 0);

            cell.Position = new MatrixCoordinates(-10, -10);
        }