Beispiel #1
0
        public override void GenerateGraphShape()
        {
            ClearAll();

            Node[,] nodeMatrix = new Node[ rowCount, colCount ];

            // Create all the nodes.
            for( int row = 0; row < rowCount; row++ )
            {
                float y = ( float )( rowCount - row - 1 );

                for( int col = 0; col < colCount; col++ )
                {
                    float x = ( float )col;

                    Node.Point location = new Node.Point( x, y );
                    Node node = CreateNode( location );
                    Insert( node );
                    nodeMatrix[ row, col ] = node;
                }
            }

            // Create all the adjacencies between the nodes.
            for( int row = 0; row < rowCount; row++ )
            {
                for( int col = 0; col < colCount; col++ )
                {
                    if( row < rowCount - 1 )
                    {
                        Adjacency adjacency = new Adjacency( nodeMatrix[ row, col ], nodeMatrix[ row + 1, col ] );
                        Insert( adjacency );
                    }

                    if( col < colCount - 1 )
                    {
                        Adjacency adjacency = new Adjacency( nodeMatrix[ row, col ], nodeMatrix[ row, col + 1 ] );
                        Insert( adjacency );
                    }
                }
            }

            mazeStart = nodeMatrix[ 0, 0 ];
            mazeFinish = nodeMatrix[ rowCount - 1, colCount - 1 ];
        }
Beispiel #2
0
        public override void GenerateGraphShape()
        {
            ClearAll();

            Node[][] nodeRingArray = new Node[ concentricCircleCount ][];

            int nodesPerRing = 7;
            float radiusDelta = 0.5f;
            float radius = 0.5f;

            for( int ringIndex = 0; ringIndex < concentricCircleCount; ringIndex++ )
            {
                Node[] nodeRing = new Node[ nodesPerRing ];
                nodeRingArray[ ringIndex ] = nodeRing;

                for( int index = 0; index < nodesPerRing; index++ )
                {
                    float angle = ( float )index / ( float )nodesPerRing * 2.0f * ( float )Math.PI;
                    float x = radius * ( float )Math.Cos( angle );
                    float y = radius * ( float )Math.Sin( angle );

                    Node.Point location = new Node.Point( x, y );
                    Node node = CreateNode( location );
                    nodeRing[ index ] = node;
                    Insert( node );
                }

                radius += radiusDelta;

                if( ringIndex < concentricCircleCount - 1 )
                {
                    float angle = ( 1.0f / ( float )nodesPerRing ) * 2.0f * ( float )Math.PI;
                    float arcLength = radius * angle;
                    if( arcLength > 1.0f )
                        nodesPerRing *= 2;
                }
            }

            Node centerNode = CreateNode( new Node.Point( 0.0f, 0.0f ) );
            Insert( centerNode );
            mazeStart = centerNode;
            mazeFinish = nodeRingArray[ concentricCircleCount - 1 ][0];

            Adjacency adjacency = new Adjacency( centerNode, nodeRingArray[0][0] );
            Insert( adjacency );

            for( int ringIndex = 0; ringIndex < concentricCircleCount; ringIndex++ )
            {
                Node[] nodeRing = nodeRingArray[ ringIndex ];
                Node[] nextNodeRing = null;
                int indexScalar = 1;
                if( ringIndex < concentricCircleCount - 1 )
                {
                    nextNodeRing = nodeRingArray[ ringIndex + 1 ];
                    if( nextNodeRing.Length > nodeRing.Length )
                        indexScalar = 2;
                }

                for( int index = 0; index < nodeRing.Length; index++ )
                {
                    int nextIndex = ( index + 1 ) % nodeRing.Length;
                    Node nodeA = nodeRing[ index ];
                    Node nodeB = nodeRing[ nextIndex ];
                    adjacency = new Adjacency( nodeA, nodeB );
                    Insert( adjacency );

                    if( nextNodeRing != null )
                    {
                        nodeA = nodeRing[ index ];
                        nodeB = nextNodeRing[ index * indexScalar ];
                        adjacency = new Adjacency( nodeA, nodeB );
                        Insert( adjacency );
                    }
                }
            }
        }