I have a grid-type map (similar to this), and i want to map the quickest path between two coordinates (eg: quickest way to get from 1,8 to 5,8). now, i've got all sections of the grid mapped out in a multidimensional array (named @grid, and used as $grid[x][y], with x as the horizontal coordinate and y as the vertical coordinate), and each array contains a text string. if you're able to go north from that point, the string will contain 'n', if you're able to go south, it would contain 's',and so on for east and west. it can contain any combination of the directions (eg: 'new' means you can go north, east, or west), so i have the following functions already:
sub isNorth { # Passed x & y coords, determines if able to go north my($x,$y) = @_; if($grid[$x][$y] =~ /n/) { return 1 # Can go north, return 1 for true } else { return 0 # Can't go north, return 0 for false } } sub isSouth { # Passed x & y coords, determines if able to go south my($x,$y) = @_; if($grid[$x][$y] =~ /s/) { return 1 # Can go south, return 1 for true } else { return 0 # Can't go south, return 0 for false } } sub isEast { # Passed x & y coords, determines if able to go east my($x,$y) = @_; if($grid[$x][$y] =~ /e/) { return 1 # Can go east, return 1 for true } else { return 0 # Can't go east, return 0 for false } } sub isWest { # Passed x & y coords, determines if able to go west my($x,$y) = @_; if($grid[$x][$y] =~ /w/) { return 1 # Can go west, return 1 for true } else { return 0 # Can't go west, return 0 for false } }
so, with all this, how can I programatically map the shortest path? (or, if there IS no path determinable from the present data, return an appropriate error message?) any & all help appreciated!

In reply to Mapping paths?... by Anonymous Monk

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.