in reply to In search of the perfect digital hexagon

Also not sure what you mean by "express perfect hexagons", but the reference to board games makes me think of a using a graph (vertices V_1... V_n, adjacency matrix A_ij=1 when edge between V_i and V_j) to represent the 6 neighbors of each cell.
  • Comment on Re: In search of the perfect digital hexagon

Replies are listed 'Best First'.
Re^2: In search of the perfect digital hexagon
by Fletch (Bishop) on Aug 13, 2004 at 13:58 UTC

    Another way is to use a two dimensional array (matrix), but only some locations are valid. Empire uses a scheme sort of like this:

        ---------0000000000111111111
        9876543210123456789012345678
     -8        . . . - -             -8
     -7       . . . . - ^            -7
     -6    . . . . - - - -           -6
     -5   . . - . a a - ^ ? ? -      -5
     -4  . . . . k o ! - ^ ? ? ?     -4
     -3 . - . a h j a ^ ^ ^ ^ ^ -    -3
     -2  . . - . a a a ^ a a - - -   -2
     -1   . . . a a a b + + ^ ^ -    -1
      0  . . . m c u a a - ^ - ^     0
      1   . - . a a . a a - - ^      1
      2    - ^ ^ a a a ^ a - - ^     2
      3     - - - - - - - . . -      3
      4      ^ - - - - - ^ - -       4
      5       - ^ - - ^ - - -        5
        ---------0000000000111111111
        9876543210123456789012345678
    

    (From the docs for the map command)

    To move east or west you use an increment of two to the x index (i.e. west would be ( x - 2, y )); north / south is forbidden in this scheme since the faces are lined up W/NW/NE/E/SE/SW, although that's by convention and there's nothing saying you couldn't rule out east / west by adding to y instead (and in effect rotating the hex grid 90 degrees). To move any of the other four directions you add/subtract one to both coordinates (northeast would be ( x + 1, y - 1)). You can easily verify if a coordinate pair's valid as both x and y have to be both odd or both even.

    If this is anywhere near what you were asking about you might take a gander at PEI, the Perl Empire Interface, which has code for dealing with maps of this type.