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.
23 /* TODO: better EPD knowlege */
24 enum EPD_TASKS
{ EPD_BEST_MOVE
, EPD_AVOID_MOVE
};
26 /* load EPD positions from file and solve them */
27 void *run_epd_test(void *args
)
31 struct epd_info_t
*ei
;
32 char dummy
[MAX_STRING
];
33 char target_move1
[MAX_STRING
];
34 char target_move2
[MAX_STRING
];
35 char epd_line
[MAX_STRING
];
36 char epd_type
[MAX_STRING
];
37 int epd_count
, epd_processed
, epd_solved
, epd_task
;
39 /* args - struct epd_info_t */
40 ei
= (struct epd_info_t
*)args
;
41 epd_file
= fopen(ei
->filename
, "r");
44 fprintf(stderr
, "EPD error: %s\n", strerror(errno
));
56 set_engine_value(&e
.thinking
, TRUE
);
57 set_engine_value(&e
.fixed_time
, TRUE
);
59 while (fgets(epd_line
, MAX_STRING
, epd_file
)) {
60 fprintf(stdout
, "EPD: %s", epd_line
);
62 /* seek for first test */
63 if (++epd_count
< ei
->first_test
)
66 if (!setup_board(epd_line
)) {
67 /* handle incorrect lines */
68 fprintf(stderr
, "Invalid EPD!\n");
72 int target_moves
= sscanf(epd_line
, "%s %s %s %s %s %[1-8a-hNBRQKx+#]"\
73 " %[1-8a-hNBRQKx+#]", dummy
, dummy
, dummy
, dummy
, epd_type
, \
74 target_move1
, target_move2
) - 5;
76 /* invalid epd position */
80 if (!strncmp(epd_type
, "bm", 2))
81 epd_task
= EPD_BEST_MOVE
;
82 else if ((target_moves
> 1) && !strncmp(epd_type
, "am", 2))
83 epd_task
= EPD_AVOID_MOVE
;
89 /* set maximum search depth and convert time from seconds */
90 set_engine_value(&e
.max_depth
, 64);
91 set_engine_value(&e
.max_time
, ei
->think_time
* 100);
93 /* clear transposition table and start search */
94 clear_main_hashtable();
95 clear_pawn_hashtable();
100 san_move(move
, dummy
);
102 /* did we found the move? */
103 if (!strncmp(dummy
, target_move1
, 6)) {
104 if (epd_task
== EPD_BEST_MOVE
)
106 } else if ((target_moves
> 1) && !strncmp(dummy
, target_move2
, 6)) {
107 if (epd_task
== EPD_BEST_MOVE
)
112 fprintf(stdout
, "\n* Tested EPD's = %d, solved = %d, percent = %.2f%%, " \
113 "total = %d.\n\n", epd_processed
, epd_solved
, \
114 ((float)epd_solved
/ epd_processed
) * 100, epd_count
);
116 if (epd_count
>= ei
->max_tests
)
120 set_engine_value(&e
.fixed_time
, FALSE
);
121 set_engine_value(&e
.thinking
, FALSE
);