File: gen-move-funcs.pl

package info (click to toggle)
freecell-solver 5.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,256 kB
  • sloc: ansic: 28,700; perl: 10,050; xml: 5,600; python: 1,339; sh: 533; cpp: 275; makefile: 20; javascript: 8
file content (77 lines) | stat: -rw-r--r-- 1,809 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;
use Path::Tiny qw/ path /;
use FindBin ();
use lib "$FindBin::Bin/../t/lib";
use FC_Solve::MoveFuncs;

my $move_funcs          = FC_Solve::MoveFuncs::move_funcs();
my $declared_move_funcs = FC_Solve::MoveFuncs::declared_move_funcs();
my $aliases             = FC_Solve::MoveFuncs::aliases();

my $move_funcs_decl =
"fc_solve_solve_for_state_move_func fc_solve_sfs_move_funcs[FCS_MOVE_FUNCS_NUM]";
my $aliases_decl =
    "fcs_move_func_aliases_mapping fc_solve_sfs_move_funcs_aliases[256]";

my $GEN =
    "// This file is generated by gen-move-funcs.pl.\n// Do not edit by hand!";

path('move_funcs_maps.h')->spew_utf8(<<"EOF");
$GEN
#pragma once
#define FCS_MOVE_FUNCS_NUM @{[0+@$move_funcs]}
#define FCS_MOVE_FUNCS_ALIASES_NUM @{[0+keys%$aliases]}

typedef uint8_t fcs_move_func_aliases_mapping;

extern $move_funcs_decl;
extern $aliases_decl;
EOF

sub func_name
{
    my $f = shift;
    my $s = "fc_solve_sfs_$f";
    return
          $f =~ /simple_simon/  ? "WRAP_SIMPSIM($s)"
        : $f =~ /freecell|_fc_/ ? "WRAP_ZEROFC($s)"
        :                         $s;
}

my $move_funcs_string = join( ",\n",
    ( map { "    " . func_name( $_->{'function'} ) } @$move_funcs ) );
my $aliases_string = join(
    ',',
    map {
        my $c = $aliases->{ chr($_) };
        defined($c) ? $declared_move_funcs->{$c} : 0
    } 0 .. ( 256 - 1 )
);
path('move_funcs_maps.c')->spew_utf8(<<"EOF");
$GEN
#include "freecell.h"
#include "simpsim.h"

#ifdef FCS_DISABLE_SIMPLE_SIMON
#define WRAP_SIMPSIM(f) fc_solve_sfs_move_top_stack_cards_to_founds
#else
#define WRAP_SIMPSIM(f) f
#endif

#if MAX_NUM_FREECELLS > 0
#define WRAP_ZEROFC(f) f
#else
#define WRAP_ZEROFC(f) fc_solve_sfs_null_move_func
#endif

$move_funcs_decl =
{
$move_funcs_string
};

$aliases_decl =
{
$aliases_string
};
EOF