Hi
You might want to take a look at the code of a game called "MAZE". It works with a 2 dimentional map, keeps track of your current position and gives you valid directions to make it through the MAZE. Maybe this gives you a good insperation.

Here is a copy of it:

#!/usr/bin/perl -w use strict; my @maze=( [ qw( e swe we ws ) ], [ qw( se new sw ns ) ], [ qw( ns - ns n ) ], [ qw( ne w ne w ) ], ); my %direction=( n=> [ -1, 0], s=> [1, 0], e=> [ 0, 1], w=> [0, -1]); my %full=( e => 'East', n => 'North', w=>'West', s=>'South'); my($curr_x, $curr_y, $x, $y)=(0,0,3,3); my $move; sub disp_location { my($cx, $cy)=@_; print "You may move "; while($maze[$cx][$cy]=~/([nsew])/g) { print "$full{$1} "; } print "($maze[$cx][$cy])\n"; } sub move_to { my($new, $xref, $yref)=@_; $new=substr(lc($new),0,1); if ($maze[$$xref][$$yref]!~/$new/) { print "Invalid direction, $new.\n"; return; } $$xref += $direction{$new}[0]; $$yref += $direction{$new}[1]; } until ( $curr_x == $x and $curr_y == $y ) { disp_location($curr_x, $curr_y); print "Which way? "; $move=<STDIN>; chomp $move; exit if ($move=~/^q/); move_to($move, \$curr_x, \$curr_y); } print "You made it through the maze!\n";

(Provided by "SAMS Teach yourself Perl in 24 Hours")

Good luck!
Marcel

200604 Janitored by Corion: Added formatting


In reply to Re: Closed geometry: a train track problem by Anonymous Monk
in thread Closed geometry: a train track problem by SamCG

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.