File: Test-connected-components-ID.pl

package info (click to toggle)
freecell-solver 3.26.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,864 kB
  • ctags: 3,658
  • sloc: ansic: 34,721; perl: 12,320; xml: 5,999; python: 1,149; sh: 965; ruby: 347; cpp: 304; makefile: 151
file content (107 lines) | stat: -rw-r--r-- 2,944 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/perl

use strict;
use warnings;

use Games::Solitaire::Verify::Solution;

open my $dump_fh, '<', '982.dump'
    or die "Cannot open 982.dump";

my $initial_state_str;
my $initial_board;

my $two_fc_variant = Games::Solitaire::Verify::VariantsMap->new->get_variant_by_id('freecell');

$two_fc_variant->num_freecells(2);

my %components = ();
my %states_to_components = ();

while (my $line = <$dump_fh>)
{
    if (($line =~ m{^Foundations}) .. ($line !~ /\S/))
    {
        my $state_str = '';
        while ($line !~ /\S/)
        {
            $state_str .= $line;
            $line = <$dump_fh>;
        }
        # $state_str is now ready.
        if (!defined($initial_state_str))
        {
            $initial_state_str = $state_str;
            $initial_board = Games::Solitaire::Verify::State->new(
                {
                    string => $initial_state_str,
                    variant => "custom",
                    variant_params => $two_fc_variant,
                }
            );
        }

        my $board = Games::Solitaire::Verify::State->new(
            {
                string => $initial_state_str,
                variant => "custom",
                variant_params => $two_fc_variant,
            }
        );

        my $found_str = join(',',
            map { $board->get_foundation_value($_, 0) } (0 .. 3)
        );

        my @columns_non_free_lens;

        foreach my $col_idx (0 .. ($board->num_columns - 1))
        {
            my $col = $board->get_column($col_idx);

            my $get_non_free_len = sub {
                my $non_free_len = $col->len();

                while ($non_free_len > 1)
                {
                    my $child = $col->pos($non_free_len-1);
                    my $parent = $col->pos($non_free_len-2);

                    if (not (($child->color() ne $parent->color())
                        &&
                        ($child->rank()+1 == $parent->rank())))
                    {
                        return $non_free_len;
                    }
                }
                continue
                {
                    $non_free_len--;
                }
                return 0;
            };

            push @columns_non_free_lens, $get_non_free_len->();
        }

        my $component_id = $found_str . ';' . join(',', @columns_non_free_lens);

        if (exists($states_to_components{$state_str}))
        {
            if ($states_to_components{$state_str} ne $component_id)
            {
                die "MisMATCH! <<<$state_str>>> ; <<<$component_id>>> ; <<<$states_to_components>>>";
            }
        }
        elsif (exists($components{$component_id}))
        {
            die "Two component IDs with different components - <<<$component_id>>>!";
        }
        else
        {
            $components{$component_id} = 1;
            # Do a BrFS scan on the fully connected component.

        }
    }
}