2

If I have to iterate through a table of hexagonal cells checking for text inside them by conducting a recursive depth first search, arranged as shown: [Typing it out on StackOverflow apparently doesn't keep the formatting.]

Example 1:

enter image description here

Example 2:

enter image description here

What would be the best way to identifying them as "cells?" In other words, besides removing the textual diagonal lines and converting them into a 2D array with just numbers in it, what would be the best way to tell the computer in code to recognize x certain number of y characters resembles a "cell?"

Thanks in advance.

1 Answer 1

1

Easiest way to represent a hexagonal grid would be plain 2-d array with special rule about neighborhood of the cells. Take your second case for example, in matrix form it would be:

char M[][] = 

{
 { 'b', 'g', 'g', 'b', ' ' },
 { 'g', ' ', 'B', 'B', 'B' },
 { 'g', 'B', ' ', 'b', 'g' },
 { 'B', ' ', 'g', 'g', 'g' }
}

Element in column m in row n is neighbor with:

  • elements in columns m and m + 1 in row n - 1
  • elements in columns m - 1 and m + 1 in row n
  • elements in columns m - 1 and m in row n + 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.