My Project
main.c
Go to the documentation of this file.
1
11#include "board.h"
12#include "cassio.h"
13#include "hash.h"
14#include "obftest.h"
15#include "options.h"
16#include "perft.h"
17#include "search.h"
18#include "stats.h"
19#include "ui.h"
20#include "util.h"
21
22#include <locale.h>
23
27void version(void)
28{
29 fprintf(stderr, "Edax version " VERSION_STRING " " __DATE__ " " __TIME__);
30
31#if defined(__linux__)
32 fprintf(stderr, " for Linux\n");
33#elif defined(_WIN32)
34 fprintf(stderr, " for Windows\n");
35#elif defined(__APPLE__)
36 fprintf(stderr, " for Apple\n");
37#else
38 fprintf(stderr, "\n");
39#endif
40#ifdef DEBUG
41 fprintf(stderr, " This is debug module.\n\n");
42#endif
43
44 fprintf(stderr, "copyright 1998 - 2017 Richard Delorme\n\n");
45}
46
47
51void usage(void)
52{
53 fprintf(stderr, "Usage: edax <protocol> <options>\n");
54 fprintf(stderr, "User Interface Protocols:\n");
55 fprintf(stderr, " -edax Edax's user interface (default)\n");
56 fprintf(stderr, " -ggs Generic Game Server interface (play through internet)\n");
57 fprintf(stderr, " -gtp Go Text Protocol.\n");
58 fprintf(stderr, " -xboard xboard/winboard protocol.\n");
59 fprintf(stderr, " -nboard NBoard protocol.\n");
60 fprintf(stderr, " -cassio Cassio protocol.\n");
61 fprintf(stderr, " -solve <problem_file> Automatic problem solver/checker.\n");
62 fprintf(stderr, " -wtest <wthor_file> Test edax using WThor's theoric score.\n");
63 fprintf(stderr, " -count <level> Count positions up to <level>.\n");
65}
66
75int main(int argc, char **argv)
76{
77 UI *ui;
78 int i, r, level = 0, size = 8;
79 char *problem_file = NULL;
80 char *wthor_file = NULL;
81 char *count_type = NULL;
82 int n_bench = 0;
83
84 // options.n_task default to system cpu number
86
87 // options from edax.ini
88 options_parse("edax.ini");
89
90 // allocate ui
91 ui = (UI*) malloc(sizeof *ui);
92 if (ui == NULL) fatal_error("Cannot allocate a user interface.\n");
93 ui->type = UI_EDAX;
94 ui->init = ui_init_edax;
95 ui->free = ui_free_edax;
96 ui->loop = ui_loop_edax;
97
98 // parse arguments
99 for (i = 1; i < argc; i++) {
100 char *arg = argv[i];
101 while (*arg == '-') ++arg;
102 if (strcmp(arg, "v") == 0 || strcmp(arg, "version") == 0) version();
103 else if (ui_switch(ui, arg)) ;
104 else if ((r = (options_read(arg, argv[i + 1]))) > 0) i += r - 1;
105 else if (strcmp(arg, "solve") == 0 && argv[i + 1]) problem_file = argv[++i];
106 else if (strcmp(arg, "wtest") == 0 && argv[i + 1]) wthor_file = argv[++i];
107 else if (strcmp(arg, "bench") == 0 && argv[i + 1]) n_bench = atoi(argv[++i]);
108 else if (strcmp(arg, "count") == 0 && argv[i + 1]) {
109 count_type = argv[++i];
110 if (argv[i + 1]) level = string_to_int(argv[++i], 0);
111 if (argv[i + 1] && strcmp(argv[i + 1], "6x6") == 0) {
112 size = 6;
113 ++i;
114 }
115
116
117 }
118 else usage();
119 }
121
122 // initialize
129
130 // solver & tester
131 if (problem_file || wthor_file || n_bench) {
132 Search search[1];
133 search_init(search);
134 search->options.header = " depth|score| time | nodes (N) | N/s | principal variation";
135 search->options.separator = "------+-----+--------------+-------------+----------+---------------------";
137 if (problem_file) obf_test(search, problem_file, NULL);
138 if (wthor_file) wthor_test(wthor_file, search);
139 if (n_bench) obf_speed(search, n_bench);
140 search_free(search);
141
142 } else if (count_type){
143 Board board[1];
144 board_init(board);
145 if (strcmp(count_type, "games") == 0) quick_count_games(board, level, size);
146 else if (strcmp(count_type, "positions") == 0) count_positions(board, level, size);
147 else if (strcmp(count_type, "shapes") == 0) count_shapes(board, level, size);
148
149 } else if (ui->type == UI_CASSIO) {
150 engine_loop();
151
152 // other protocols
153 } else {
154 ui_event_init(ui);
155 ui->init(ui);
156 ui->loop(ui);
157 if (ui->free) ui->free(ui);
158 ui_event_free(ui);
159 }
160
161 // display statistics
162 statistics_print(stdout);
163
164
165 // free;
166 eval_close();
167 options_free();
168 free(ui);
169
170 return 0;
171}
172
void wthor_test(const char *file, Search *search)
Test Search with a wthor base.
Definition base.c:516
void edge_stability_init(void)
Initialize the edge stability tables.
Definition board.c:956
void board_init(Board *board)
Set a board to the starting position.
Definition board.c:280
void engine_loop(void)
Loop event.
Definition cassio.c:683
@ UI_EDAX
Definition const.h:110
@ UI_CASSIO
Definition const.h:109
#define VERSION_STRING
Definition const.h:88
void ui_loop_edax(UI *ui)
Loop event.
Definition edax.c:284
void ui_init_edax(UI *ui)
initialize edax protocol.
Definition edax.c:137
void ui_free_edax(UI *ui)
free resources used by edax protocol.
Definition edax.c:157
void eval_close(void)
Free global resources allocated to the evaluation function.
Definition eval.c:494
void eval_open(const char *file)
Load the evaluation function features' weights.
Definition eval.c:265
int main()
Definition generate_count_flip.c:362
void hash_move_init(void)
Initialize global hash move data.
Definition hash-lock-free.c:70
void hash_code_init(void)
Initialize global hash code data.
Definition hash-lock-free.c:52
void usage(void)
Programme usage.
Definition main.c:51
void version(void)
Print version & copyright.
Definition main.c:27
void obf_speed(Search *search, const int n)
Definition obftest.c:534
void obf_test(Search *search, const char *obf_file, const char *wrong_file)
Test an OBF file.
Definition obftest.c:294
Problem solver.
void options_usage(void)
Print options usage.
Definition options.c:90
void options_free(void)
free allocated resources.
Definition options.c:399
Options options
Definition options.c:22
int options_read(const char *option, const char *value)
Read an option.
Definition options.c:136
void options_parse(const char *file)
parse options from a file
Definition options.c:266
void options_bound(void)
Keep options between realistic values.
Definition options.c:288
void quick_count_games(const Board *board, const int depth, const int size)
Count games.
Definition perft.c:521
void count_shapes(const Board *board, const int depth, const int size)
Count shapes.
Definition perft.c:1077
void count_positions(const Board *board, const int depth, const int size)
Count positions.
Definition perft.c:822
Move generator test header file.
void search_init(Search *search)
Init the main search.
Definition search.c:351
void search_free(Search *search)
Free the search allocated ressource.
Definition search.c:441
void search_global_init(void)
Definition search.c:151
void statistics_init(void)
Intialization of the statistics.
Definition stats.c:26
void statistics_print(FILE *f)
Print statistics.
Definition stats.c:112
Statistics header.
Definition board.h:26
int n_task
Definition options.h:29
char * eval_file
Definition options.h:57
int verbosity
Definition options.h:32
Definition search.h:95
const char * separator
Definition search.h:145
const char * header
Definition search.h:144
struct Search::@25 options
Definition ui.h:31
int type
Definition ui.h:36
void(* init)(struct UI *)
Definition ui.h:40
void(* loop)(struct UI *)
Definition ui.h:41
void(* free)(struct UI *)
Definition ui.h:42
void ui_event_init(UI *ui)
Create a new Othello User Interface.
Definition ui.c:206
bool ui_switch(UI *ui, const char *ui_type)
Switch between different User Interface.
Definition ui.c:25
void ui_event_free(UI *ui)
Free events.
Definition ui.c:220
User interface header.
int string_to_int(const char *s, const int default_value)
Convert a string into an integer.
Definition util.c:457
int get_cpu_number(void)
Get the number of cpus or cores on the machine.
Definition util.c:987
Miscellaneous utilities header.
#define fatal_error(...)
Display an error message as "FATAL_ERROR : file name : function name : line number : ....
Definition util.h:349