예제 #1
0
        public void Open(int row, int col)
        {
            var squareIndex = GetIndex(row, col);

            if (_squareOpenStatus[squareIndex] == false)
            {
                _squareOpenStatus[squareIndex] = true;

                //Up
                if (row > 1)
                {
                    _graphManager.ConnectNodes(squareIndex, GetIndex(row - 1, col));
                }

                //Down
                if (row < _dimension)
                {
                    _graphManager.ConnectNodes(squareIndex, GetIndex(row + 1, col));
                }

                //Left
                if (col > 1)
                {
                    _graphManager.ConnectNodes(squareIndex, GetIndex(row, col - 1));
                }

                //Right
                if (col < _dimension)
                {
                    _graphManager.ConnectNodes(squareIndex, GetIndex(row, col + 1));
                }
            }
        }
예제 #2
0
        public void InitializeGraphManager()
        {
            var size = (_dimension * _dimension);

            //Initialize open status array
            _squareOpenStatus = new bool[size];

            //Total Node size is dimension squared plus two helper nodes for top and bottom rows
            _graphManager  = _createGraphManager(size + 2);
            _capNodeIndex  = size;
            _baseNodeIndex = size + 1;

            //Connect the top and bottom row to the extra elements
            //This will allow easy percolation test
            var bottomRowStartIndex = _dimension * (_dimension - 1);

            for (var i = 0; i < _dimension; ++i)
            {
                //Top row
                _graphManager.ConnectNodes(_capNodeIndex, i);
                //Bottom row
                _graphManager.ConnectNodes(_baseNodeIndex, bottomRowStartIndex + 1);
            }
        }
 public void WhenIConnectNodeWithNode(int p0, int p1)
 {
     _gm.ConnectNodes(p0,p1);
 }