-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsengine.c
135 lines (114 loc) · 3.28 KB
/
sengine.c
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* sengine.c
* (c) 2017-2018, Brian Stephenson
* brian@bstephen.me.uk
*
* A program to test orthodox chess problems of the types:
*
* directmates
* selfmates
* relfexmates
* helpmates
*
* Input is taken from the program options and output is xml on stdout.
*
* This is the main control module that contains the 'main' function.
*/
#include "sengine.h"
extern enum STIP opt_stip;
extern uint64_t positions_got;
extern uint64_t boards_got;
extern uint64_t boardlists_got;
extern uint64_t positions_freed;
extern uint64_t boards_freed;
extern uint64_t boardlists_freed;
static clock_t prog_start, prog_end;
static double run_time;
enum SOUNDNESS sound;
void end_clock(void)
{
prog_end = clock();
run_time = (double)(prog_end - prog_start) / CLOCKS_PER_SEC;
return;
}
int main(int argc, char* argv[])
{
int rc;
prog_start = clock();
rc = do_options(argc, argv);
if (rc == 0) {
BOARD* init_pos;
init();
init_mem();
if (opt_stip == HELP) {
init_pos = setup_diagram(WHITE);
} else {
init_pos = setup_diagram(BLACK);
}
rc = validate_board(init_pos);
if (rc == 0) {
switch (opt_stip) {
case DIRECT: {
DIR_SOL* dir_sol;
dir_sol = (DIR_SOL*) calloc(1, sizeof(DIR_SOL));
SENGINE_MEM_ASSERT(dir_sol);
solve_direct(dir_sol, init_pos);
start_dir();
if (dir_sol->set != NULL) {
add_dir_set(dir_sol->set);
freeBoardlist(dir_sol->set);
}
if (dir_sol->tries != NULL) {
add_dir_tries(dir_sol->tries);
freeBoardlist(dir_sol->tries);
}
if (dir_sol->keys != NULL) {
add_dir_keys(dir_sol->keys);
freeBoardlist(dir_sol->keys);
}
add_dir_options();
add_dir_stats(dir_sol);
end_clock();
time_dir(run_time);
end_dir();
free(dir_sol);
break;
}
case SELF:
(void) fputs("sengine ERROR: Can't solve selfmates yet!",
stderr);
exit(1);
break;
case REFLEX:
(void) fputs("sengine ERROR: Can't solve reflexmates yet!",
stderr);
exit(1);
break;
case HELP:
(void) fputs("sengine ERROR: Can't solve helpmates yet!",
stderr);
exit(1);
break;
default:
(void) fputs("sengine ERROR: impossible invalid stipulation!!",
stderr);
exit(1);
break;
}
close_mem();
} else {
close_mem();
prog_end = clock();
run_time = (double)(prog_end - prog_start) / CLOCKS_PER_SEC;
(void) fprintf(stderr, "Running Time = %f\n", run_time);
}
}
return rc;
}
int tzcount(BITBOARD inBrd)
{
if (inBrd == 0) {
return 64;
}
return __builtin_ctzll(inBrd);
}