/[symmetry-circle]/symmetry.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /symmetry.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1 by dpavlin, Sun Aug 26 02:53:41 2007 UTC revision 2 by dpavlin, Sun Aug 26 09:20:07 2007 UTC
# Line 6  Line 6 
6    
7  use strict;  use strict;
8    
 use Data::Dump qw/dump/;  
   
9  my $board = << '_BOARD_';  my $board = << '_BOARD_';
10  +-+-+-+-+-+-+-+-+  +-+-+-+-+-+-+-+-+
11  | |   |o| |     |  | |   |o| |     |
# Line 51  my @move_by = ( 1, $ll, -1, -$ll ); Line 49  my @move_by = ( 1, $ll, -1, -$ll );
49  my $step = 0;   # right  my $step = 0;   # right
50    
51  # offset 0, top-left corner  # offset 0, top-left corner
52  my $pos = 0;  my $pos = shift @ARGV || 0;
 $pos = 2;  
 $pos = 6;  
53    
54  my @trace = ('x') x ( $#board + 1 );  my @trace = ('x') x ( $#board + 1 );
55  sub trace {  sub trace {
# Line 82  sub follow { Line 78  sub follow {
78  my $ok_path = qr/[\|\-]/;  my $ok_path = qr/[\|\-]/;
79    
80  sub can_turn {  sub can_turn {
81          my $step = shift;          my $try_step = shift;
82          die "no step?" unless defined $step;          die "no step?" unless defined $try_step;
83    
84            $try_step %= 4;
85    
86          my $turn_pos = $pos + $move_by[ $step % 4 ];          my $turn_pos = $pos + $move_by[$try_step];
87    
88          my $old = $trace[ $turn_pos ];          my $old = $trace[ $turn_pos ];
89          $trace[ $turn_pos ] = '?';          $trace[ $turn_pos ] = '?';
# Line 93  sub can_turn { Line 91  sub can_turn {
91          $trace[ $turn_pos ] = $old;          $trace[ $turn_pos ] = $old;
92    
93          if ( $board[ $turn_pos ] =~ $ok_path ) {          if ( $board[ $turn_pos ] =~ $ok_path ) {
94                  warn "OK can_turn $step_name[$step] turn_pos = $turn_pos b($board[$turn_pos]) t($trace[$turn_pos])";                  warn "OK can_turn $try_step $step_name[$try_step] turn_pos = $turn_pos b($board[$turn_pos]) t($trace[$turn_pos])";
95                    $step = $try_step;
96                  return 1;                  return 1;
97          } else {          } else {
98                  warn "NOPE can_turn $step_name[$step] turn_pos = $turn_pos b($board[$turn_pos]) t($trace[$turn_pos])";                  warn "NOPE can_turn $try_step $step_name[$try_step] turn_pos = $turn_pos b($board[$turn_pos]) t($trace[$turn_pos])";
99                  return 0;                  return 0;
100          }          }
101  }  }
# Line 112  while( 1 ) { Line 111  while( 1 ) {
111          } elsif ( $board[ $next_pos ] =~ $ok_path ) {          } elsif ( $board[ $next_pos ] =~ $ok_path ) {
112                  warn "OK next_pos = $next_pos b($board[$next_pos]) t($trace[$next_pos])\n";                  warn "OK next_pos = $next_pos b($board[$next_pos]) t($trace[$next_pos])\n";
113                  move;                  move;
114                  follow( $step+1 ) if can_turn( $step+1 );                  can_turn( $step + 1 );
115          } else {          } else {
116                  warn "find line continuation from $step $step_name[$step]...\n";                  warn "find line continuation from $step $step_name[$step]...\n";
117                  foreach my $o ( -1, 1 ) {                  can_turn( $step - 1 ) || can_turn( $step + 1 ) || die "can't find new direction";
                         if ( can_turn( $step + $o ) ) {  
                                 $step = $step+$o;  
                                 warn "new direction: $step $step_name[$step]\n";  
                                 follow( $step );  
                                 last;  
                         }  
                 }  
118          }          }
119          warn draw( @trace );          warn draw( @trace );
120    

Legend:
Removed from v.1  
changed lines
  Added in v.2

  ViewVC Help
Powered by ViewVC 1.1.26