Commits

Anonymous committed bed95a8

Convert the states to array refs.

Comments (0)

Files changed (1)

abc-path/generator/generate-abs-path.pl

     return;
 }
 
+my $LAYOUT_FIELD = 0;
+my $LAST_CELL_FIELD = 1;
+
 {
 my @get_next_cells_lookup =
 (
 {
     my ($self, $state, $init_idx) = @_;
 
-    my $l = $state->{layout};
+    my $l = $state->[$LAYOUT_FIELD];
 
     return [ grep { vec($l, $_, 8) == 0 }
         @{$get_next_cells_lookup[$init_idx]}
 {
     my ($self, $state) = @_;
 
-    my $cells = $self->_get_next_cells($state, $state->{last_cell});
+    my $cells = $self->_get_next_cells($state, $state->[$LAST_CELL_FIELD]);
     $self->_fisher_yates_shuffle($cells);
-    $state->{cells} = $cells;
+    push @$state, $cells;
 
     return;
 }
     my $init_layout = '';
     vec($init_layout, $init_xy, 8) = 1;
 
-    my $initial_state =
-    { layout => $init_layout, last_cell => $init_xy}
-    ;
-
+    my $initial_state = [$init_layout, $init_xy];
     $self->_fill_next_cells($initial_state);
     
     my @dfs_stack = ($initial_state);
     while (@dfs_stack)
     {
         my $last_state = $dfs_stack[-1];
-        my $l = $last_state->{layout};
+        my ($l, undef, $last_cells) = @$last_state;
 
         if (@dfs_stack == $BOARD_SIZE)
         {
         # print "Last state = " . Dumper($last_state) . "\n";
         # print "Layout = \n" . $self->get_layout_as_string($last_state->{layout}) . "\n";
 
-        my $next_idx = shift(@{$last_state->{cells}});
+        my $next_idx = shift(@$last_cells);
 
         if (!defined($next_idx))
         {
 
         my $next_layout = $l;
         vec($next_layout, $next_idx, 8) = 1+@dfs_stack;
-        my $next_state =
-        {
-            layout => $next_layout,
-            last_cell => $next_idx,
-        };
-
+        my $next_state = [$next_layout, $next_idx];
         $self->_fill_next_cells($next_state);
 
         push @dfs_stack, $next_state;