/[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 7 by dpavlin, Sun Aug 26 14:45:26 2007 UTC revision 12 by dpavlin, Fri Aug 31 15:17:11 2007 UTC
# Line 119  sub follow { Line 119  sub follow {
119  my $ok_path = qr/[\|\-]/;  my $ok_path = qr/[\|\-]/;
120    
121  my @corners;  my @corners;
122    my $corners_usage;
123    
124  sub can_turn {  sub can_turn {
125          my $try_step = shift;          my $try_step = shift;
# Line 135  sub can_turn { Line 136  sub can_turn {
136          $trace[ $turn_pos ] = $old;          $trace[ $turn_pos ] = $old;
137    
138          if ( $board[ $turn_pos ] =~ $ok_path ) {          if ( $board[ $turn_pos ] =~ $ok_path ) {
139                  my $xy = x_y($turn_pos);                  my $xy = x_y($pos);
140                  warn "OK can_turn $try_step $step_name[$try_step] turn_pos = $turn_pos b($board[$turn_pos]) t($trace[$turn_pos]) to $xy\n";                  warn "OK can_turn $try_step $step_name[$try_step] turn_pos = $turn_pos b($board[$turn_pos]) t($trace[$turn_pos]) from $xy\n";
141                  $step = $try_step;                  $step = $try_step;
142                  push @corners, $xy;                  push @corners, $xy;
143                    $corners_usage->{$xy}++;
144                  return 1;                  return 1;
145          } else {          } else {
146                  warn "NOPE can_turn $try_step $step_name[$try_step] turn_pos = $turn_pos b($board[$turn_pos]) t($trace[$turn_pos])\n";                  warn "NOPE can_turn $try_step $step_name[$try_step] turn_pos = $turn_pos b($board[$turn_pos]) t($trace[$turn_pos])\n";
# Line 170  sub shape { Line 172  sub shape {
172          my $len = 0;          my $len = 0;
173          $step = 0;          $step = 0;
174    
175          warn "<<< shape from $x,$y pos: $pos\n";          my $usage = $corners_usage->{"$x,$y"} || 0;
176    
177            warn "<<< shape from $x,$y [usage: $usage] pos: $pos\n";
178    
179            if ( $usage > 4 ) {
180                    warn "SKIPPED, usage > 4\n";
181                    return 0;
182            }
183    
184          while( 1 ) {          while( 1 ) {
185    
# Line 198  sub shape { Line 207  sub shape {
207    
208          push @shapes_found, { x => $x, y => $y, len => $len, directions => show_directions };          push @shapes_found, { x => $x, y => $y, len => $len, directions => show_directions };
209    
210          warn "### corners: ",join(' ', @corners),"\n";          warn "### corners: ",join(' ', map { $_ . " [" . $corners_usage->{$_} . "]" } @corners),"\n";
211          warn ">>> ended at $pos, line length: $len, directions traversed: ",show_directions,"\n";          warn ">>> ended at $pos, line length: $len, directions traversed: ",show_directions,"\n";
212    
213          foreach my $c ( @corners ) {          foreach my $c ( @corners ) {
# Line 223  foreach my $start ( @shapes_start ) { Line 232  foreach my $start ( @shapes_start ) {
232          }          }
233  }  }
234    
235    sub is_symmetric {
236            my $path = shift || die "no path?";
237    
238            my $h = length($path)/2;
239            return 0 if int($h) != $h;
240            my ($l,$r) = ( substr($path,0,$h), substr($path,$h) );
241            $r =~ tr/lrud/rldu/;
242    #       warn "$l -- $r\n";
243            return 0 unless $l eq $r;
244            return 1;
245    }
246    
247  print ">>> RESULTS:\n";  print ">>> RESULTS:\n";
248  foreach my $r ( @shapes_found ) {  foreach my $r ( @shapes_found ) {
249          printf "%2d,%-2d len: %-4d directions: %s\n", $r->{x}, $r->{y}, $r->{len}, $r->{directions};          printf "%2d,%-2d len: %-4d directions: %s %s\n",
250            $r->{x}, $r->{y}, $r->{len},
251            is_symmetric($r->{directions}) ? 'OK' : '!!',
252            $r->{directions},
253            ;
254  }  }

Legend:
Removed from v.7  
changed lines
  Added in v.12

  ViewVC Help
Powered by ViewVC 1.1.26