in reply to Mapping paths?...
I don't remember where I first read this (it may have been here from someone like tilly), but the phrase "put the regularity in code, the irregularity in data" comes to mind. The phrase "never type the same thing twice" also springs in here.
You'll want a data structure that can tell you if you can go a direction. You'll want a way of determining the new cell number if you go that direction. Perhaps some data structure would help, like:
Then you can do things like:my %offset = ('n' => [0, 1], 's' => [0, -1], 'e' => [1, 0], 'w' => [-1 +, 0]);
In fact, I don't even like the regularity in that code. {grin} But I'll probably stop optimizing there.my $new_x = $old_x + $offset{$direction}[0]; my $new_y = $old_y + $offset{$direction}[1];
-- Randal L. Schwartz, Perl hacker
|
|---|