Skip to main content
added 115 characters in body
Source Link

Here are 2 screenshots of a land mass with 2 different randomly-created regions using the Flood-Fill algorithm.

enter image description here enter image description here

enter image description here enter image description here

Here are 2 screenshots of a land mass with 2 different randomly-created regions using the Flood-Fill algorithm.

enter image description here enter image description here

added 172 characters in body
Source Link

enter image description here enter image description here

enter image description here enter image description here

deleted 3 characters in body
Source Link
private void Assign_Hexes_to_Regions ( final Random RNG, List <Integer> frontier_hex_IDs, List <Integer> accompanying_frontier_region_IDs, final Function <Coords, List <Coords>> function_all_adjacent_coords ) { // // use a Flood-Fill technique to assign EACH Hex to EXACTLY ONE PartitionRegion // while ( frontier_hex_IDs.size() > 0 ) { // // Randomly select one of the UNASSIGNED Hexes // int random_index = RNG.nextInt( frontier_hex_IDs.size() ); int random_vertex_ID = frontier_hex_IDs.remove( random_index ); int random_region_ID = accompanying_frontier_region_IDs.remove( random_index ); Integer existing_region_ID = this.hex_ID_to_partition_ID.get( random_hex_ID ); if ( existing_region_ID == null ) { // // NO PartitionRegion assigned (yet) to this (Random) Hex // this.Assign_Hex_ID_to_Region( random_hex_ID, random_region_ID, frontier_hex_IDs, accompanying_frontier_region_IDs, function_all_adjacent_coords ); } else if ( existing_region_ID != random_region_ID ) { // // This Hex was PREVIOUSLY assigned to a DIFFERENT Region. Thus, // this Hex is at a Region Boundary // this.Get_Region( existing_region_ID ).Add_Boundary_Hex_ID( random_hex_ID ); } } private void Assign_Hex_ID_to_Region ( final int hex_ID, final int region_ID, List <Integer> frontier_hex_IDs, List <Integer> accompanying_frontier_region_IDs, final Function <Coords, List <Coords>> function_all_adjacent_coords ) { // // Assigns the Hex to the specified Region // this.Set_Region_ID_for_Hex_ID( hex_ID, region_ID ); // // Add Adjacent Hexes to the Flood-Fill possibilities // // note: the Get_All_Adjacent_Coords() function determines if the Coordinates Wrap-Around or not // for ( Coords adjacent_vertex_coords : function_all_adjacent_coords.apply( this.space_subset.Get_Space().Get_Coords_from_Vertex_ID( vertex_ID ) ) ) { if ( this.space_subset.Get_Space().Has_Coords( adjacent_vertex_coords ) ) { Integer adjacent_hex_ID = this.space_subset.Get_Space().Get_Hex_ID_from_Coords( adjacent_hex_coords ); if ( this.space_subset.Is_in_Subset( adjacent_hex_ID ) ) { frontier_hex_IDs.add( adjacent_hex_ID ); accompanying_frontier_region_IDs.add( region_ID ); } // // do NOT Add the Adjacent Hex if it is NOTOFF inon the SubsetLand Mass // } // // do NOT Add the Adjacent Hex if it is NOT on the Map (incl. Wrap-Around) // } } 
private void Assign_Hexes_to_Regions ( final Random RNG, List <Integer> frontier_hex_IDs, List <Integer> accompanying_frontier_region_IDs, final Function <Coords, List <Coords>> function_all_adjacent_coords ) { // // use a Flood-Fill technique to assign EACH Hex to EXACTLY ONE Partition // while ( frontier_hex_IDs.size() > 0 ) { // // Randomly select one of the UNASSIGNED Hexes // int random_index = RNG.nextInt( frontier_hex_IDs.size() ); int random_vertex_ID = frontier_hex_IDs.remove( random_index ); int random_region_ID = accompanying_frontier_region_IDs.remove( random_index ); Integer existing_region_ID = this.hex_ID_to_partition_ID.get( random_hex_ID ); if ( existing_region_ID == null ) { // // NO Partition assigned (yet) to this (Random) Hex // this.Assign_Hex_ID_to_Region( random_hex_ID, random_region_ID, frontier_hex_IDs, accompanying_frontier_region_IDs, function_all_adjacent_coords ); } else if ( existing_region_ID != random_region_ID ) { // // This Hex was PREVIOUSLY assigned to a DIFFERENT Region. Thus, // this Hex is at a Region Boundary // this.Get_Region( existing_region_ID ).Add_Boundary_Hex_ID( random_hex_ID ); } } private void Assign_Hex_ID_to_Region ( final int hex_ID, final int region_ID, List <Integer> frontier_hex_IDs, List <Integer> accompanying_frontier_region_IDs, final Function <Coords, List <Coords>> function_all_adjacent_coords ) { // // Assigns the Hex to the specified Region // this.Set_Region_ID_for_Hex_ID( hex_ID, region_ID ); // // Add Adjacent Hexes to the Flood-Fill possibilities // // note: the Get_All_Adjacent_Coords() function determines if the Coordinates Wrap-Around or not // for ( Coords adjacent_vertex_coords : function_all_adjacent_coords.apply( this.space_subset.Get_Space().Get_Coords_from_Vertex_ID( vertex_ID ) ) ) { if ( this.space_subset.Get_Space().Has_Coords( adjacent_vertex_coords ) ) { Integer adjacent_hex_ID = this.space_subset.Get_Space().Get_Hex_ID_from_Coords( adjacent_hex_coords ); if ( this.space_subset.Is_in_Subset( adjacent_hex_ID ) ) { frontier_hex_IDs.add( adjacent_hex_ID ); accompanying_frontier_region_IDs.add( region_ID ); } // // do NOT Add the Adjacent Hex if it is NOT in the Subset // } // // do NOT Add the Adjacent Hex if it is NOT on the Map (incl. Wrap-Around) // } } 
private void Assign_Hexes_to_Regions ( final Random RNG, List <Integer> frontier_hex_IDs, List <Integer> accompanying_frontier_region_IDs, final Function <Coords, List <Coords>> function_all_adjacent_coords ) { // // use a Flood-Fill technique to assign EACH Hex to EXACTLY ONE Region // while ( frontier_hex_IDs.size() > 0 ) { // // Randomly select one of the UNASSIGNED Hexes // int random_index = RNG.nextInt( frontier_hex_IDs.size() ); int random_vertex_ID = frontier_hex_IDs.remove( random_index ); int random_region_ID = accompanying_frontier_region_IDs.remove( random_index ); Integer existing_region_ID = this.hex_ID_to_partition_ID.get( random_hex_ID ); if ( existing_region_ID == null ) { // // NO Region assigned (yet) to this (Random) Hex // this.Assign_Hex_ID_to_Region( random_hex_ID, random_region_ID, frontier_hex_IDs, accompanying_frontier_region_IDs, function_all_adjacent_coords ); } else if ( existing_region_ID != random_region_ID ) { // // This Hex was PREVIOUSLY assigned to a DIFFERENT Region. Thus, // this Hex is at a Region Boundary // this.Get_Region( existing_region_ID ).Add_Boundary_Hex_ID( random_hex_ID ); } } private void Assign_Hex_ID_to_Region ( final int hex_ID, final int region_ID, List <Integer> frontier_hex_IDs, List <Integer> accompanying_frontier_region_IDs, final Function <Coords, List <Coords>> function_all_adjacent_coords ) { // // Assigns the Hex to the specified Region // this.Set_Region_ID_for_Hex_ID( hex_ID, region_ID ); // // Add Adjacent Hexes to the Flood-Fill possibilities // // note: the Get_All_Adjacent_Coords() function determines if the Coordinates Wrap-Around or not // for ( Coords adjacent_vertex_coords : function_all_adjacent_coords.apply( this.space_subset.Get_Space().Get_Coords_from_Vertex_ID( vertex_ID ) ) ) { if ( this.space_subset.Get_Space().Has_Coords( adjacent_vertex_coords ) ) { Integer adjacent_hex_ID = this.space_subset.Get_Space().Get_Hex_ID_from_Coords( adjacent_hex_coords ); if ( this.space_subset.Is_in_Subset( adjacent_hex_ID ) ) { frontier_hex_IDs.add( adjacent_hex_ID ); accompanying_frontier_region_IDs.add( region_ID ); } // // do NOT Add the Adjacent Hex if it is OFF on the Land Mass // } // // do NOT Add the Adjacent Hex if it is NOT on the Map (incl. Wrap-Around) // } } 
deleted 3 characters in body
Source Link
Loading
added 2532 characters in body
Source Link
Loading
deleted 2511 characters in body
Source Link
Loading
deleted 21 characters in body
Source Link
Loading
added 54 characters in body
Source Link
Loading
Source Link
Loading