Commits

Shlomi Fish committed 0e112f6

Optimisation: now pre-calculating the clues_positions.

This is instead of calcuating them again and again in run-time.

  • Participants
  • Parent commits 0df0a0e

Comments (0)

Files changed (1)

abc-path/Games-ABC_Path-Generator/lib/Games/ABC_Path/Generator.pm

 
 =cut
 
+my @_clues_positions =
+(
+    map {
+    my $clue_idx = $_;
+    [map { __PACKAGE__->_xy_to_int($_) } 
+    (
+    ($clue_idx == 0)
+    ? (map { [$_,$_] } (0 .. $LEN-1))
+    : ($clue_idx == 1)
+    ? (map { [$_,4-$_] } ( 0 .. $LEN-1))
+    : ($clue_idx < (2+5))
+    ? (map { [$clue_idx-2,$_] } (0 .. $LEN-1))
+    : (map { [$_, $clue_idx-(2+5)] } (0 .. $LEN-1))
+    )
+    ]
+    } (0 .. $NUM_CLUES-1)
+);
+
 sub calc_riddle
 {
     my ($self) = @_;
             my @positions =
             (
                 grep { !vec($last_state->{pos_taken}, $_, 1) } 
-                (
-                    map { $self->_xy_to_int($_) }
-                    (($clue_idx == 0)
-                        ? (map { [$_,$_] } (0 .. $LEN-1))
-                        : ($clue_idx == 1)
-                        ? (map { [$_,4-$_] } ( 0 .. $LEN-1))
-                        : ($clue_idx < (2+5))
-                        ? (map { [$clue_idx-2,$_] } (0 .. $LEN-1))
-                        : (map { [$_, $clue_idx-(2+5)] } (0 .. $LEN-1))
-                    )
-                )
+                @{$_clues_positions[$clue_idx]}
             );
 
             my @pairs;