AI-Pathfinding-OptimizeMultiple
view release on metacpan or search on metacpan
lib/AI/Pathfinding/OptimizeMultiple/DataInputObj.pm view on Meta::CPAN
open my $in, "<", $fn;
$id = <$in>;
chomp($id);
close($in);
open my $out, ">", $fn;
print {$out} ( $id + 1 );
close($out);
return $id;
}
sub get_prev_scans
{
my ($self) = @_;
my @prev_scans;
my $scans_fn = $self->_get_scans_registry_file_path;
open my $in, "<", $scans_fn
or die "Could not open '$scans_fn' - $!.";
while ( my $line = <$in> )
{
chomp($line);
my ( $scan_id, $cmd_line ) = split( /\t/, $line );
push @prev_scans, { 'id' => $scan_id, 'cmd_line' => $cmd_line };
}
close($in);
return \@prev_scans;
}
sub _get_scan_cmd_line
{
my $self = shift;
my $args = shift;
my $min_board = $args->{'min'} || 1;
my $max_board = $args->{'max'} || 32_000;
my $id = $args->{'id'};
my $argv = $args->{'argv'};
my @fc_num = (
exists( $args->{'freecells_num'} )
? ( "--freecells-num", $args->{'freecells_num'} )
: ()
);
my @variant = (
exists( $args->{'variant'} )
? ( "--variant", $args->{'variant'} )
: ()
);
return [
qw(freecell-solver-fc-pro-range-solve),
$min_board,
$max_board,
"20",
@variant,
'--total-iterations-limit',
( $ENV{FC_SOLVE_RANGE_ITERS_LIMIT} // 100000 ),
'--binary-output-to',
"data/$id.data.bin",
@$argv,
@fc_num,
];
}
sub time_scan
{
my $self = shift;
my $args = shift;
my $min_board = $args->{'min'} || 1;
my $max_board = $args->{'max'} || 32_000;
my $id = $args->{'id'};
my $cmd_line = $self->_get_scan_cmd_line($args);
open my $from_cmd, "-|", @$cmd_line
or die "Could not start '@$cmd_line'";
open my $fcs_out, ">", "data/$id.fcs.moves.txt";
open my $fc_pro_out, ">", "data/$id.fcpro.moves.txt";
$fcs_out->autoflush(1);
$fc_pro_out->autoflush(1);
while ( my $line = <$from_cmd> )
{
print $line;
chomp($line);
if ( $line =~ m{\A\[\[Num FCS Moves\]\]=(.*)\z}o )
{
print {$fcs_out} "$1\n";
}
elsif ( $line =~ m{\A\[\[Num FCPro Moves\]\]=(.*)\z}o )
{
print {$fc_pro_out} "$1\n";
}
}
close($from_cmd);
close($fcs_out);
close($fc_pro_out);
}
sub get_scan_ids_aref
{
my $self = shift;
return [ map { $_->id() } @{ $self->selected_scans } ];
}
sub lookup_scan_idx_based_on_id
{
my ( $self, $scan_id ) = @_;
my $idx = $self->_scan_ids_to_indexes->{$scan_id};
if ( !defined($idx) )
{
die "Index '$idx' does not exist!";
}
( run in 0.518 second using v1.01-cache-2.11-cpan-71847e10f99 )