Don't display SEE score when printing move list
[owl.git] / epd.c
blob0c6cf42bcf1041e545a745d9588f696e499e17f3
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 #include "common.h"
17 #include "board.h"
18 #include "engine.h"
19 #include "move.h"
20 #include "search.h"
22 /* TODO: better EPD knowlege */
23 enum EPD_TASKS { EPD_BEST_MOVE, EPD_AVOID_MOVE };
25 /* load EPD positions from file and solve them */
26 void *run_epd_test(void *args)
28 int move;
29 FILE *epd_file;
30 struct epd_info_t *ei;
31 char dummy[MAX_STRING];
32 char target_move1[MAX_STRING];
33 char target_move2[MAX_STRING];
34 char epd_line[MAX_STRING];
35 char epd_type[MAX_STRING];
36 int epd_count, epd_processed, epd_solved, epd_task;
38 /* args - struct epd_info_t */
39 ei = (struct epd_info_t *)args;
40 epd_file = fopen(ei->filename, "r");
42 if (!epd_file) {
43 fprintf(stderr, "EPD error: %s\n", strerror(errno));
45 /* free memory */
46 free(ei->filename);
47 free(ei);
48 return (void *)0;
51 epd_count = 0;
52 epd_processed = 0;
53 epd_solved = 0;
55 set_engine_value(&e.thinking, TRUE);
56 set_engine_value(&e.fixed_time, TRUE);
58 while (fgets(epd_line, MAX_STRING, epd_file)) {
59 fprintf(stdout, "EPD: %s", epd_line);
61 /* seek for first test */
62 if (++epd_count < ei->first_test)
63 continue;
65 if (!setup_board(epd_line)) {
66 /* handle incorrect lines */
67 fprintf(stderr, "Invalid EPD!\n");
68 continue;
71 int target_moves = sscanf(epd_line, "%s %s %s %s %s %[1-8a-hNBRQx+#]"\
72 " %[1-8a-hNBRQx+#]", dummy, dummy, dummy, dummy, epd_type, \
73 target_move1, target_move2) - 5;
75 /* invalid epd position */
76 if (target_moves < 1)
77 continue;
79 if (!strncmp(epd_type, "bm", 2))
80 epd_task = EPD_BEST_MOVE;
81 else if ((target_moves > 1) && !strncmp(epd_type, "am", 2))
82 epd_task = EPD_AVOID_MOVE;
83 else
84 continue;
86 epd_processed++;
88 /* set maximum search depth and convert time from seconds */
89 set_engine_value(&e.max_depth, 64);
90 set_engine_value(&e.max_time, ei->think_time * 100);
92 /* clear transposition table and start search */
93 move = iterate();
95 if (move) {
96 san_move(move, dummy);
98 /* did we found the move? */
99 if (!strncmp(dummy, target_move1, 6)) {
100 if (epd_task == EPD_BEST_MOVE)
101 epd_solved++;
102 } else if ((target_moves > 1) && !strncmp(dummy, target_move2, 6)) {
103 if (epd_task == EPD_BEST_MOVE)
104 epd_solved++;
108 fprintf(stdout, "\n* Tested EPD's = %d, solved = %d, percent = %.2f%%, " \
109 "total = %d.\n\n", epd_processed, epd_solved, \
110 ((float)epd_solved / epd_processed) * 100, epd_count);
112 if (epd_count >= ei->max_tests)
113 break;
116 set_engine_value(&e.fixed_time, FALSE);
117 set_engine_value(&e.thinking, FALSE);
119 /* cleanup */
120 fclose(epd_file);
121 free(ei->filename);
122 free(ei);
124 return (void *)0;