Skip to main content
edited tags
Link
user1430
user1430
Tweeted twitter.com/#!/StackGameDev/status/284917204514902016
Source Link
Chris Evans
  • 871
  • 3
  • 9
  • 15

Find connected hex of same color

I'm using Lua. I have a hex map. It is randomly generated into an table.

hexmap[y][x].color = "red"

I wish to find each "group" of hex's. i.e. all hex's of the same color that connect to each other will belong to one group.

As an example, in the following image:

Hex map

The result should be:

1 blue group (all hex's connect) 3 green groups 1 black group

Any suggestions?

Thank you.