File: range_solvers.h

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 (88 lines) | stat: -rw-r--r-- 2,528 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
78
79
80
81
82
83
84
85
86
87
88
/*
 * This file is part of Freecell Solver. It is subject to the license terms in
 * the COPYING.txt file found in the top-level directory of this distribution
 * and at http://fc-solve.shlomifish.org/docs/distro/COPYING.html . No part of
 * Freecell Solver, including this file, may be copied, modified, propagated,
 * or distributed except according to the terms contained in the COPYING file.
 *
 * Copyright (c) 2000 Shlomi Fish
 */
// range_solvers.h - common routines for the range solvers.
#pragma once
#include "rinutils.h"
#include "freecell-solver/fcs_cl.h"
#include "range_solvers_gen_ms_boards.h"
#include "handle_parsing.h"

#ifndef FCS_WITHOUT_CMD_LINE_HELP
static void print_help(void);
static __attribute__((noreturn)) __attribute__((format(printf, 1, 2))) void
help_err(const char *const msg, ...)
{
    va_list ap;
    va_start(ap, msg);
    vfprintf(stderr, msg, ap);
    va_end(ap);
    print_help();
    exit(-1);
}
#endif

static inline bool range_solvers__solve(void *const instance,
    const long long board_num, long long *const total_num_iters_temp)
{
    fcs_state_string state_string;
    get_board(board_num, state_string);

    switch (freecell_solver_user_solve_board(instance, state_string))
    {
    case FCS_STATE_SUSPEND_PROCESS:
        fc_solve_print_intractable(board_num);
        break;

    case FCS_STATE_FLARES_PLAN_ERROR:
        print_flares_plan_error(instance);
        return TRUE;

    case FCS_STATE_IS_NOT_SOLVEABLE:
        fc_solve_print_unsolved(board_num);
        break;
#ifdef FCS_RANGE_SOLVERS_PRINT_SOLVED
    case FCS_STATE_WAS_SOLVED:
        printf("Solved Board No. " FCS_LL_FMT "\n", board_num);
        break;
#endif
    }

    *total_num_iters_temp += freecell_solver_user_get_num_times_long(instance);
    return FALSE;
}

static inline int range_solvers_main(
    int argc, char *argv[], int arg, long long, long long, long long);
int main(int argc, char *argv[])
{
    if (argc < 4)
    {
#ifndef FCS_WITHOUT_CMD_LINE_HELP
        help_err("Not Enough Arguments!\n");
#else
        return -1;
#endif
    }
    int arg = 1;
    const long long next_board_num = atoll(argv[arg++]);
    const long long end_board = atoll(argv[arg++]);
    const long long stop_at = atoll(argv[arg++]);

    if (stop_at <= 0)
    {
#ifndef FCS_WITHOUT_CMD_LINE_HELP
        help_err("print_step (the third argument) must be greater than 0.\n");
#else
        return -1;
#endif
    }
    return range_solvers_main(
        argc, argv, arg, next_board_num, end_board, stop_at);
}