-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
178 lines (144 loc) · 3.6 KB
/
main.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* 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 bool opt_meson;
extern bool opt_classify;
extern enum AIM opt_aim;
extern enum STIP opt_stip;
extern unsigned int opt_moves;
static clock_t prog_start, prog_end;
static double run_time;
enum SOUNDNESS sound;
static void do_direct(BOARD*);
static void do_self(BOARD*);
static void do_help(BOARD*);
static void do_reflex(BOARD*);
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: {
do_direct(init_pos);
break;
}
case SELF:
do_self(init_pos);
break;
case REFLEX:
do_reflex(init_pos);
break;
case HELP:
do_help(init_pos);
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;
}
void do_direct(BOARD* init_pos)
{
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);
}
if (dir_sol->tries != NULL) {
add_dir_tries(dir_sol->tries);
}
if (dir_sol->keys != NULL) {
add_dir_keys(dir_sol->keys);
}
if (opt_meson == false) {
add_dir_options();
add_dir_stats(dir_sol);
}
end_clock();
if (opt_meson == false) {
time_dir(run_time);
}
end_dir();
if ((opt_classify == true) && (opt_aim == MATE) && (opt_stip == DIRECT) && (opt_moves == 2) && (sound == SOUND)) {
class_direct_2(dir_sol, init_pos);
}
if (dir_sol->set != NULL) {
freeBoardlist(dir_sol->set);
}
if (dir_sol->tries != NULL) {
freeBoardlist(dir_sol->tries);
}
if (dir_sol->keys != NULL) {
freeBoardlist(dir_sol->keys);
}
free(dir_sol);
freeBoard(init_pos);
return;
}
static void do_self(BOARD* init_pos)
{
(void) fputs("sengine ERROR: Can't solve selfmates yet!\n",
stderr);
exit(1);
return;
}
static void do_help(BOARD* init_pos)
{
(void) fputs("sengine ERROR: Can't solve helpmates yet!\n",
stderr);
exit(1);
return;
}
static void do_reflex(BOARD* init_pos)
{
(void) fputs("sengine ERROR: Can't solve reflexmates yet!\n",
stderr);
exit(1);
return;
}