1

I created a hexagon grid based on information in this article https://www.redblobgames.com/grids/hexagons/

Here's how it looks so far: Grid of hexagons

I want to divide this grid into groups similar to this: Hex grid with groups

I want to have gaps in the grid but I also need all groups to be connected. Essentially I want to be able to move from any hexagon in a group to any other hexagon in a group.

My first idea is to pick a random tile for each group then add a neighboring tile to each group until a group touches another group, then maybe have a decreasing chance of adding another tile to that group. My main concern with this is that I could end up with 2 groups that touch each other but are not connected to the rest of the groups.

Any ideas are appreciated. Let me know if you need any more information.

Andy D
  • 31
  • 4
  • 1
    Suggestion: First determine which hexes will remain blank. To do that, choose a few starting blank hexes, and extend from them with some probabilities. If the probabilities are low enough, there is reasonable chance that the remaining grid will be connected. If the remaining grid isn't connected, reset and try again. – Stef Nov 27 '21 at 20:03
  • 1
    Then, select a random tile for each region, and extend them until all the non-blank grid is filled. – Stef Nov 27 '21 at 20:04
  • 1
    PS: I personally don't intend to provide a more precise answer than my two comments, but if you do end up with a working algorithm, I'd be interested to see it; note that it's possible to post an answer to your own question. – Stef Nov 27 '21 at 20:24
  • I will start by writing an algorithm to remove tiles. Then it should be fairly easy to fill in all remaining tiles. I already wrote a simple function to remove a few random tiles. I think my next step is to remove neighboring tiles. – Andy D Nov 28 '21 at 20:08

1 Answers1

0

My solution to this was to first remove edge tiles. I did that by creating a loop that randomly selects a tile adjacent to the edge and removes it. This is repeated a random amount of times. I do this several times then remove groups of inner tiles. I first select a random tile that is not adjacent to an edge and put it in a group, select one of its neighbors that is not adjacent to an edge and repeat a random amount of times. After that is complete I get some decent looking maps.

The only other thing I had to account for was that sometimes "islands" would be created meaning 1 or a few tiles are not connected to the rest of the map. I solved this by creating a function to creates groups of adjacent tiles and delete all but the largest group.

Here is an example: enter image description here

Andy D
  • 31
  • 4