~ubuntu-branches/ubuntu/saucy/freecell-solver/saucy

« back to all changes in this revision

Viewing changes to scripts/Test-And-Statistics-982.pl

  • Committer: Package Import Robot
  • Author(s): Gergely Risko
  • Date: 2012-06-22 10:08:05 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120622100805-evoda1ccdr8vt5xr
Tags: 3.12.0-1
New upstream version. (closes: #675262)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
use strict;
 
4
use warnings;
 
5
 
 
6
use lib './t/t/lib';
 
7
use Games::Solitaire::FC_Solve::DeltaStater;
 
8
 
 
9
open my $dump_fh, '<', '982.dump'
 
10
    or die "Cannot open 982.dump for reading - $!";
 
11
 
 
12
my $line_idx = 0;
 
13
sub read_state
 
14
{
 
15
    my $ret = '';
 
16
    while (my $line = <$dump_fh>)
 
17
    {
 
18
        $line_idx++;
 
19
        if ($line =~ /\AFoundations: /)
 
20
        {
 
21
            $ret .= $line;
 
22
            $line = <$dump_fh>;
 
23
            $line_idx++;
 
24
            while ($line =~ /\S/)
 
25
            {
 
26
                $ret .= $line;
 
27
                $line = <$dump_fh>;
 
28
                $line_idx++;
 
29
            }
 
30
            return $ret;
 
31
        }
 
32
    }
 
33
    exit(0);
 
34
}
 
35
 
 
36
my $init_state_str = read_state();
 
37
 
 
38
my %encoded_counts;
 
39
 
 
40
while (my $state = read_state())
 
41
{
 
42
    my $delta = Games::Solitaire::FC_Solve::DeltaStater->new(
 
43
        {
 
44
            init_state_str => $init_state_str,
 
45
        }
 
46
    );
 
47
 
 
48
    $delta->set_derived(
 
49
        {
 
50
            state_str => $state,
 
51
        }
 
52
    );
 
53
 
 
54
    my $encoded = $delta->encode();
 
55
 
 
56
    $encoded_counts{length($encoded)}++;
 
57
 
 
58
    if ($delta->decode($encoded)->to_string() ne $state)
 
59
    {
 
60
        die "Wrong encoding/decoding process at line $line_idx!";
 
61
    }
 
62
 
 
63
    print "Counts:\n";
 
64
    print map { "$_ => $encoded_counts{$_}\n" } sort { $a <=> $b } keys(%encoded_counts);
 
65
}