public void ImageSpaceAdjacency( Bitmap bitmap, Graph.Adjacency adjacency, out System.Drawing.Point drawPointA, out System.Drawing.Point drawPointB ) { Node.Point pointA = adjacency.NodeA.Location; Node.Point pointB = adjacency.NodeB.Location; int row, col; graph.GraphSpaceToImageSpace( bitmap, ref pointA, out row, out col ); drawPointA = new System.Drawing.Point( col, row ); graph.GraphSpaceToImageSpace( bitmap, ref pointB, out row, out col ); drawPointB = new System.Drawing.Point( col, row ); }
public void Generate( int seed ) { graph.NodeCreator = MazeNodeCreator; graph.GenerateGraphShape(); if( spanningTree == null ) spanningTree = new Graph(); spanningTree.ClearAll(); foreach( Graph.Node node in graph.SetOfNodes ) spanningTree.Insert( node ); List< Graph.Adjacency > temporaryAdjacencyList = new List< Graph.Adjacency >( graph.SetOfAdjacencies.Count ); foreach( Graph.Adjacency adjacency in graph.SetOfAdjacencies ) temporaryAdjacencyList.Add( adjacency ); Random random = new Random( seed ); List< Graph.Adjacency > shuffledAdjacencyList = new List< Graph.Adjacency >( graph.SetOfAdjacencies.Count ); while( temporaryAdjacencyList.Count > 0 ) { int index = random.Next( 0, temporaryAdjacencyList.Count - 1 ); Graph.Adjacency adjacency = temporaryAdjacencyList[ index ]; temporaryAdjacencyList.RemoveAt( index ); shuffledAdjacencyList.Add( adjacency ); } int setCount = graph.SetOfNodes.Count; foreach( Graph.Adjacency adjacency in shuffledAdjacencyList ) { Node nodeA = ( Node )adjacency.NodeA; Node nodeB = ( Node )adjacency.NodeB; if( !Node.AreMembersOfSameSet( nodeA, nodeB ) ) { Node.UnifySetsForEachOf( nodeA, nodeB ); setCount--; Graph.Adjacency mazePathway = new Graph.Adjacency( nodeA, nodeB ); spanningTree.Insert( mazePathway ); } if( setCount == 1 ) break; } }