2 # This file is part of Language::Befunge.
3 # Copyright (c) 2001-2008 Jerome Quelin, all rights reserved.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the same terms as Perl itself.
10 package Language
::Befunge
::Wrapping
::LaheySpace
;
15 use base
qw{ Language
::Befunge
::Wrapping
};
21 # $wrapping->wrap( $storage, $ip );
23 # Wrap $ip in $storage according to this module wrapping algorithm. Note
24 # that $ip is already out of bounds, ie, it has been moved once by LBI.
25 # As a side effect, $ip will have its position changed.
27 # LBW::LaheySpace implements a wrapping as defined in befunge specs -
28 # ie, when hitting a bound of the storage, the ip reverses and
29 # backtraces until it bumps into another bound, and then it reverses one
30 # last time to keep its velocity.
33 my ($self, $storage, $ip) = @_;
35 # fetch the current position/velocity of the ip.
36 my $v = $ip->get_position;
37 my $d = $ip->get_delta;
39 # fetch the storage min / max
40 my $min = $storage->min;
41 my $max = $storage->max;
43 # funge98 says we should walk our current trajectory in reverse,
44 # until we hit the other side of the storage, and then continue
45 # along the same path.
48 } while ( $v->bounds_check($min, $max) );
50 # now that we've hit the wall, walk back into the valid code range.
54 $ip->set_position($v);
63 Language::Befunge::Wrapping::LaheySpace - a LaheySpace wrapping
68 C<LBW::LaheySpace> implements a wrapping as defined in befunge specs - ie,
69 when hitting a bound of the storage, the ip reverses and backtraces
70 until it bumps into another bound, and then it reverses one last time to
77 =head2 LBW::LaheySpace->new;
79 Creates a new LaheySpace wrapping.
84 =head2 $wrapping->wrap( $storage, $ip )
86 Wrap C<$ip> in C<$storage> according to this module wrapping algorithm.
87 See L<DESCRIPTION> for an overview of the algorithm used.
89 Note that C<$ip> is already out of bounds, ie, it has been moved once by
92 As a side effect, $ip will have its position changed.
103 Jerome Quelin, C<< <jquelin@cpan.org> >>
106 =head1 COPYRIGHT & LICENSE
108 Copyright (c) 2001-2008 Jerome Quelin, all rights reserved.
110 This program is free software; you can redistribute it and/or modify
111 it under the same terms as Perl itself.