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.


In reply to Re^2: In search of the perfect digital hexagon by Fletch
in thread In search of the perfect digital hexagon by coreolyn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.