37
37
#include "unused.h"
40
enum STANDARD_NOTATION_TYPE
43
STANDARD_NOTATION_REGULAR,
44
STANDARD_NOTATION_EXTENDED
48
struct fc_solve_display_information_context_struct
50
fcs_bool_t debug_iter_state_output;
54
fcs_bool_t parseable_output;
55
fcs_bool_t canonized_order_output;
56
fcs_bool_t display_10_as_t;
57
fcs_bool_t display_parent_iter_num;
58
fcs_bool_t debug_iter_output_on;
59
fcs_bool_t display_moves;
60
fcs_bool_t display_states;
61
int standard_notation;
62
const char * output_filename;
65
typedef struct fc_solve_display_information_context_struct fc_solve_display_information_context_t;
67
static void init_debug_context(
68
fc_solve_display_information_context_t * dc
71
dc->debug_iter_state_output = FALSE;
72
dc->parseable_output = FALSE;
73
dc->canonized_order_output = FALSE;
74
dc->display_10_as_t = FALSE;
75
dc->display_parent_iter_num = FALSE;
76
dc->display_moves = FALSE;
77
dc->display_states = TRUE;
78
dc->standard_notation = STANDARD_NOTATION_NO;
79
dc->output_filename = NULL;
41
#include "portable_time.h"
43
#include <sys/types.h>
46
#include "output_to_file.h"
82
48
static void my_iter_handler(
83
49
void * user_instance,
466
439
*ret = EXIT_AND_RETURN_0;
467
440
return FCS_CMD_LINE_STOP;
469
else if (!strncmp(argv[arg], "--help-", 7))
442
else if (!strncmp(arg_str, "--help-", 7))
471
print_help_string(argv[arg]+7);
444
print_help_string(arg_str+7);
472
445
*ret = EXIT_AND_RETURN_0;
473
446
return FCS_CMD_LINE_STOP;
475
else if ((!strcmp(argv[arg], "-i")) || (!strcmp(argv[arg], "--iter-output")))
448
else if (IS_ARG("-i") || IS_ARG("--iter-output"))
477
450
#define set_iter_handler() \
478
451
freecell_solver_user_set_iter_handler( \
485
458
set_iter_handler();
487
else if ((!strcmp(argv[arg], "-s")) || (!strcmp(argv[arg], "--state-output")))
460
else if (IS_ARG("-s") || IS_ARG("--state-output"))
489
462
set_iter_handler();
490
463
dc->debug_iter_state_output = TRUE;
491
464
#undef set_iter_handler
493
else if ((!strcmp(argv[arg], "-p")) || (!strcmp(argv[arg], "--parseable-output")))
466
else if (IS_ARG("-p") || IS_ARG("--parseable-output"))
495
468
dc->parseable_output = TRUE;
497
else if ((!strcmp(argv[arg], "-c")) || (!strcmp(argv[arg], "--canonized-order-output")))
470
else if (IS_ARG("-c") || IS_ARG("--canonized-order-output"))
499
472
dc->canonized_order_output = TRUE;
501
else if ((!strcmp(argv[arg], "-o")) || (!strcmp(argv[arg], "--output")))
474
else if (IS_ARG("-o") || IS_ARG("--output"))
509
482
dc->output_filename = (const char *)argv[arg];
510
483
return FCS_CMD_LINE_SKIP;
512
else if ((!strcmp(argv[arg], "-t")) || (!strcmp(argv[arg], "--display-10-as-t")))
485
else if (IS_ARG("-t") || IS_ARG("--display-10-as-t"))
514
487
dc->display_10_as_t = TRUE;
516
else if ((!strcmp(argv[arg], "-m")) || (!strcmp(argv[arg], "--display-moves")))
489
else if (IS_ARG("-m") || IS_ARG("--display-moves"))
518
491
dc->display_moves = TRUE;
519
492
dc->display_states = FALSE;
521
else if ((!strcmp(argv[arg], "-sn")) || (!strcmp(argv[arg], "--standard-notation")))
494
else if (IS_ARG("-sn") || IS_ARG("--standard-notation"))
523
496
dc->standard_notation = STANDARD_NOTATION_REGULAR;
526
else if ((!strcmp(argv[arg], "-snx")) || (!strcmp(argv[arg], "--standard-notation-extended")))
499
else if (IS_ARG("-snx") || IS_ARG("--standard-notation-extended"))
528
501
dc->standard_notation = STANDARD_NOTATION_EXTENDED;
530
else if ((!strcmp(argv[arg], "-sam")) || (!strcmp(argv[arg], "--display-states-and-moves")))
503
else if (IS_ARG("-sam") || IS_ARG("--display-states-and-moves"))
532
505
dc->display_moves = TRUE;
533
506
dc->display_states = TRUE;
535
else if ((!strcmp(argv[arg], "-pi")) || (!strcmp(argv[arg], "--display-parent-iter")))
508
else if (IS_ARG("-pi") || IS_ARG("--display-parent-iter"))
537
510
dc->display_parent_iter_num = TRUE;
539
else if ((!strcmp(argv[arg], "--reset")))
512
else if (IS_ARG("-sel") || IS_ARG("--show-exceeded-limits"))
514
dc->show_exceeded_limits = TRUE;
516
else if (IS_ARG("--reset"))
541
518
init_debug_context(dc);
542
519
freecell_solver_user_set_iter_handler(
623
601
"-snx", "--standard-notation-extended",
624
602
"-sam", "--display-states-and-moves",
625
603
"-pi", "--display-parent-iter",
604
"-sel", "--show-exceeded-limits",
626
605
"-o", "--output",
671
650
freecell_solver_user_free(instance);
675
(parser_ret == FCS_CMD_LINE_PARAM_WITH_NO_ARG)
653
else if (parser_ret == FCS_CMD_LINE_PARAM_WITH_NO_ARG)
678
655
fprintf(stderr, "The command line parameter \"%s\" requires an argument"
679
656
" and was not supplied with one.\n", argv[arg]);
683
(parser_ret == FCS_CMD_LINE_ERROR_IN_ARG)
659
else if (parser_ret == FCS_CMD_LINE_ERROR_IN_ARG)
686
661
if (error_string != NULL)
753
728
ret = freecell_solver_user_resume_solution(instance);
731
#elif defined(FCS_TRACE_MEM)
735
char stat_fn[1024], foo_str[1024];
736
fcs_portable_time_t mytime;
739
unsigned long long unsigned_foo;
741
snprintf(stat_fn, sizeof(stat_fn), "/proc/%ld/stat", (long)(getpid()));
743
freecell_solver_user_limit_iterations(instance, limit);
744
ret = freecell_solver_user_solve_board(instance, user_state);
745
while (ret == FCS_STATE_SUSPEND_PROCESS)
747
FCS_GET_TIME(mytime);
749
/* This was taken from:
751
* http://www.brokestream.com/procstat.html
753
stat = fopen(stat_fn, "r");
754
#define readone(foo) (fscanf(stat, "%lld ", &rss))
755
#define readstr(foo) (fscanf(stat, "%1000s ", foo_str))
756
#define readchar(foo) (fscanf(stat, "%c ", foo_str))
757
#define readunsigned(foo) (fscanf(stat, "%llu ", &unsigned_foo))
777
readone(&num_threads);
778
readone(&it_real_value);
779
readunsigned(&start_time);
789
printf("Reached:\t%d\t%li.%.6li\t%lld\n",
791
FCS_TIME_GET_SEC(mytime),
792
FCS_TIME_GET_USEC(mytime),
798
freecell_solver_user_limit_iterations(instance, limit);
799
ret = freecell_solver_user_resume_solution(instance);
757
804
ret = freecell_solver_user_solve_board(instance, user_state);
799
846
output_fh = stdout;
802
if (ret == FCS_STATE_WAS_SOLVED)
804
fprintf(output_fh, "-=-=-=-=-=-=-=-=-=-=-=-\n\n");
811
move_dump = output_fh;
813
if (debug_context.display_states)
816
freecell_solver_user_current_state_as_string(
818
debug_context.parseable_output,
819
debug_context.canonized_order_output,
820
debug_context.display_10_as_t
823
fprintf(move_dump, "%s\n", as_string);
827
fprintf(move_dump, "%s", "\n====================\n\n");
831
freecell_solver_user_get_next_move(
837
if (debug_context.display_moves)
840
freecell_solver_user_move_to_string_w_state(
843
debug_context.standard_notation
846
if (debug_context.display_states && debug_context.standard_notation)
848
fprintf(move_dump, "Move: ");
853
(debug_context.standard_notation ?
860
if (debug_context.standard_notation)
862
if ((move_num % 10 == 0) || debug_context.display_states)
864
fprintf(move_dump, "\n");
867
if (debug_context.display_states)
869
fprintf(move_dump, "\n");
875
if (debug_context.display_states)
878
freecell_solver_user_current_state_as_string(
880
debug_context.parseable_output,
881
debug_context.canonized_order_output,
882
debug_context.display_10_as_t
885
fprintf(move_dump, "%s\n", as_string);
890
if (debug_context.display_states || (!debug_context.standard_notation))
892
fprintf(move_dump, "%s", "\n====================\n\n");
896
if (debug_context.standard_notation && (!debug_context.display_states))
898
fprintf(move_dump, "\n\n");
902
fprintf(output_fh, "This game is solveable.\n");
906
fprintf (output_fh, "I could not solve this game.\n");
911
"Total number of states checked is %i.\n",
912
freecell_solver_user_get_num_times(instance)
917
"This scan generated %i states.\n",
918
freecell_solver_user_get_num_states_in_collection(instance)
849
fc_solve_output_result_to_file(
850
output_fh, instance, ret, &debug_context
922
853
if (debug_context.output_filename)