33 t = time(NULL); date = localtime(&t);
34 wheader->
century = date->tm_year / 100 + 19;
35 wheader->
year = date->tm_year % 100;
36 wheader->
month = date->tm_mon + 1;
37 wheader->
day = date->tm_mday;
41 else wheader->
game_year = date->tm_year + 1900;
58 r = fread(&wheader->
century, 1, 1, f);
59 r += fread(&wheader->
year, 1, 1, f);
60 r += fread(&wheader->
month, 1, 1, f);
61 r += fread(&wheader->
day, 1, 1, f);
62 r += fread(&wheader->
n_games, 4, 1, f);
63 r += fread(&wheader->
n, 2, 1, f);
67 r += fread(&wheader->
depth, 1, 1, f);
68 r += fread(&wheader->
reserved, 1, 1, f);
71 warn(
"Cannot read wthor header (r = %d)\n", r);
88 r = fwrite(&wheader->
century, 1, 1, f);
89 r += fwrite(&wheader->
year, 1, 1, f);
90 r += fwrite(&wheader->
month, 1, 1, f);
91 r += fwrite(&wheader->
day, 1, 1, f);
92 r += fwrite(&wheader->
n_games, 4, 1, f);
93 r += fwrite(&wheader->
n, 2, 1, f);
94 r += fwrite(&wheader->
game_year, 2, 1, f);
96 r += fwrite(&wheader->
game_type, 1, 1, f);
97 r += fwrite(&wheader->
depth, 1, 1, f);
98 r += fwrite(&wheader->
reserved, 1, 1, f);
101 warn(
"Cannot write wthor header (r = %d)\n", r);
116 base->
player = (char (*)[20]) malloc(
sizeof (*base->
player));
118 strncpy(base->
player[0],
"?", 20);
120 warn(
"Cannot allocate Wthor players' array\n");
139 if ((f = fopen(file,
"rb")) == NULL) {
140 warn(
"Cannot open Wthor players' file %s\n", file);
141 fprintf(stderr,
"Creating a new %s file\n\n", file);
153 r += fread(base->
player[i], 20, 1, f);
156 warn(
"Cannot allocate Wthor players' array\n");
160 warn(
"Error while reading Wthor players' file %s %d/%d\n", file, r, base->
n_players);
184 if ((f = fopen(file,
"wb")) == NULL) {
185 warn(
"Cannot open Wthor players' file %s\n", file);
192 r += fwrite(base->
player[i], 20, 1, f);
196 warn(
"Error while reading Wthor players' file %s %d/%d\n", file, r, base->
n_players);
215 assert(base != NULL && name != NULL);
219 if (strcmp(name, base->
player[i]) == 0)
return i;
223 player = (char (*)[20]) realloc(base->
player, n * sizeof (*base->
player));
227 strncpy(base->
player[i], name, 20);
228 base->
player[i][19] =
'\0';
230 warn(
"Cannot allocate Wthor players' array\n");
252 if ((f = fopen(file,
"rb")) == NULL) {
253 warn(
"Cannot open Wthor tournaments' file %s\n", file);
266 warn(
"Cannot allocate Wthor tournaments' array\n");
285static void wthor_tournaments_save(WthorBase *base, const char *file)
293 if ((f = fopen(file,
"rw")) == NULL) {
294 warn(
"Cannot open Wthor tournaments' file %s\n", file);
299 for (i = r = 0; i < base->n_tournaments; ++i) {
300 r += fwrite(base->tournament[i], 26, 1, f);
302 if (r != base->n_tournaments) {
303 warn(
"Error while writing %s %d/%d\n", file, r, base->n_tournaments);
335 char path[FILENAME_MAX];
346 if ((f = fopen(file,
"rb")) != NULL) {
353 if (!r)
warn(
"Error while reading %s\n", file);
355 warn(
"Cannot allocate whor games\n");
362 warn(
"Cannot open file %s\n", file);
390 char path[FILENAME_MAX];
396 if ((f = fopen(file,
"wb")) != NULL) {
402 if (r != base->
n_games)
warn(
"Error while writing %s\n", file);
405 warn(
"Cannot open file %s\n", file);
426 for (i = 0; i < base->
n_games; ++i, ++j) {
432 warn(
"Cannot allocate wthor games\n");
450 if (0 <= i && i < base->n_games) {
452 fprintf(f,
"Game #%d: %s: %4d - %s vs. %s: ",
462 fprintf(f,
"Score final : %+02d (as black disc count.)\n", base->
game[i].
score);
481 for (i = 0; i < 60 - n_empties && game->
x[i]; ++i) {
544 warn(
"Incomplete or Illegal game: %d empties\n", n_empties);
551 if (abs(score) > 64) {
552 warn(
"Impossible theoric score:\n");
565 warn(
"Wrong theoric score: %+d (Wthor) instead of %+d (Edax)\n", score, search->
result->
score);
574 n_err =
pv_check(board, &pv, search);
579 fprintf(stderr,
"setboard %s\nplay ",
board_to_string(board, player, s));
581 putc(
'\n', stderr); putc(
'\n', stderr);
587 printf(
"%s game: %4d, error: %2d ; ", file, (
int)(wthor - base->
game) + 1, n_failure);
588 printf(
"%lld n, ", n_nodes);
time_print(t,
false, stdout); putchar(
'\r');
630 if (abs(score) > 64) {
638 ++histogram[search->
result->
score + 64][(score + 64) / 2];
700 int size = base->
size;
702 if (size == 0) size = 16384;
704 ptr = (
Game*) realloc(base->
game, size * sizeof (
Game));
706 error(
"cannot reallocate base game");
725 for (i = k = 0; i < base->
n_games; ++i) {
726 for (j = 0, found =
false; j < k && !found; ++j)
728 if (!found) base->
game[k++] = base->
game[i];
755 else if (strcmp(ext,
".edx") == 0) load =
game_read;
757 warn(
"Unknown game format extension: %s\n", ext);
762 else f = fopen(file,
"r");
764 warn(
"Cannot open file %s\n", file);
768 info(
"loading games...");
772 if (ferror(f) || feof(f))
break;
802 else if (strcmp(ext,
".wtb") == 0) {
808 }
else if (strcmp(ext,
".edx") == 0) save =
game_write;
810 warn(
"Unknown game format extension: %s\n", ext);
816 for (i = 0; i < base->
n_games; ++i) {
820 f = fopen(file,
"w");
822 warn(
"Cannot open file %s\n", file);
825 for (i = 0; i < old.
n_games && !ferror(f); ++i) {
826 save(old.
game + i, f);
848 f = fopen(problem,
"w");
850 for (i = 0; i < base->
n_games; ++i) {
853 fprintf(f,
"%s\n", s);
873 f = fopen(problem,
"w");
875 for (i = 0; i < base->
n_games; ++i) {
898 for (i = 0; i < base->
n_games; ++i) {
901 n_error =
game_analyze(base->
game + i, search, n_empties, apply_correction);
903 printf(
"Game #%d contains %d errors", i, n_error);
904 if (apply_correction) {
905 if (
game_analyze(base->
game + i, search, n_empties,
false)) printf(
"... correction failed! ***BUG DETECTED!***\n");
906 else printf(
"... corrected!\n");
907 }
else putchar(
'\n');
909 printf(
"%d/%d %.1f %% done.\r", i + 1, base->
n_games, 100.0 * (i + 1) / base->
n_games); fflush(stdout);
924 for (i = n = 0; i < base->
n_games; ++i) {
928 if (completed || (i % 1000) == 0) {
929 printf(
"%d/%d games completed (%.1f %% done).\r", n, i + 1, 100.0 * (i + 1) / base->
n_games); fflush(stdout);
932 printf(
"%d/%d games completed (all done). \n", n, i + 1);
945 Base base_1[1], base_2[2];
949 long long n_1, n_2, n_2_only;
959 for (i = 0; i < base_1->
n_games; ++i) {
962 for (j = 0; j < 60 && game->
move[j] !=
NOMOVE; ++j) {
972 for (i = 0; i < base_2->
n_games; ++i) {
975 for (j = 0; j < 60 && game->
move[j] !=
NOMOVE; ++j) {
985 for (i = 0; i < base_2->
n_games; ++i) {
988 for (j = 0; j < 60 && game->
move[j] !=
NOMOVE; ++j) {
999 printf(
"%s : %lld positions - %lld original positions\n", file_1, n_1, n_1 - (n_2- n_2_only));
1000 printf(
"%s : %lld positions - %lld original positions\n", file_2, n_2, n_2_only);
1001 printf(
"%lld common positions\n", n_2-n_2_only);
static bool wthor_header_write(WthorHeader *wheader, FILE *f)
Read wthor header.
Definition base.c:84
void base_to_problem(Base *base, const int n_empties, const char *problem)
Convert a game database to a set of problems.
Definition base.c:841
void base_analyze(Base *base, Search *search, const int n_empties, const bool apply_correction)
Base analysis.
Definition base.c:893
static void wthor_players_save(WthorBase *base, const char *file)
Load wthor players.
Definition base.c:174
bool base_load(Base *base, const char *file)
Load a game database.
Definition base.c:740
void base_save(const Base *base, const char *file)
Save a game database.
Definition base.c:788
void base_complete(Base *base, Search *search)
Base analysis.
Definition base.c:919
void wthor_edaxify(const char *file)
Change players to "Edax (delorme)" and tourney to "Etudes" in a wthor base.
Definition base.c:651
void base_to_FEN(Base *base, const int n_empties, const char *problem)
Convert a game database to a set of problems.
Definition base.c:867
static void wthor_players_init(WthorBase *base)
Init wthor players.
Definition base.c:113
static void wthor_header_set(WthorHeader *wheader, unsigned int n_games, unsigned int n, unsigned int year)
Set wthor header.
Definition base.c:28
void wthor_init(WthorBase *base)
Initialize a Wthor base.
Definition base.c:316
static void wthor_players_load(WthorBase *base, const char *file)
Load wthor players.
Definition base.c:131
void base_unique(Base *base)
Make games unique in the game database.
Definition base.c:720
void wthor_eval(const char *file, Search *search, unsigned long long histogram[129][65])
Test Eval with a wthor base.
Definition base.c:611
void base_init(Base *base)
Initialize a game database.
Definition base.c:672
void wthor_print_game(WthorBase *base, int i, FILE *f)
print a wthor game.
Definition base.c:446
bool wthor_save(WthorBase *base, const char *file)
Save a wthor base.
Definition base.c:387
bool base_to_wthor(const Base *base, WthorBase *wthor)
Convert to a wthor base.
Definition base.c:417
static void wthor_tournaments_load(WthorBase *base, const char *file)
Load wthor tournaments.
Definition base.c:243
int wthor_player_get(WthorBase *base, const char *name)
Get a Wthor player's index.
Definition base.c:210
bool wthor_load(WthorBase *base, const char *file)
Load a wthor base.
Definition base.c:332
void wthor_free(WthorBase *base)
Free a wthor base.
Definition base.c:373
static void wthorgame_get_board(WthorGame *game, const int n_empties, Board *board, int *player)
Get a position from a Wthor game.
Definition base.c:474
void wthor_test(const char *file, Search *search)
Test Search with a wthor base.
Definition base.c:516
void base_append(Base *base, const Game *game)
Add a game to a game database.
Definition base.c:696
void base_free(Base *base)
Free resources of a game database.
Definition base.c:684
int pv_check(const Board *init_board, Line *pv, Search *search)
Verify that a PV does not contain errors.
Definition base.c:502
static bool wthor_header_read(WthorHeader *wheader, FILE *f)
Read wthor header.
Definition base.c:54
void base_compare(const char *file_1, const char *file_2)
Base Compare.
Definition base.c:943
#define foreach_wthorgame(wgame, wbase)
Definition base.h:62
bool board_check_move(const Board *board, Move *move)
Check if a move is legal.
Definition board.c:452
void board_print_FEN(const Board *board, const int player, FILE *f)
print using FEN description.
Definition board.c:1297
bool board_is_game_over(const Board *board)
Check if the game is over.
Definition board.c:1203
void board_print(const Board *board, const int player, FILE *f)
Print out the board.
Definition board.c:1230
void board_update(Board *board, const Move *move)
Update a board.
Definition board.c:469
int board_count_empties(const Board *board)
Check if the game is over.
Definition board.c:1216
unsigned long long board_get_move(const Board *board, const int x, Move *move)
Compute a move.
Definition board.c:438
void board_init(Board *board)
Set a board to the starting position.
Definition board.c:280
char * board_to_string(const Board *board, const int player, char *s)
convert the to a compact string.
Definition board.c:1272
bool board_is_pass(const Board *board)
Check if current player should pass.
Definition board.c:1191
void board_pass(Board *board)
Passing move.
Definition board.c:503
@ NOMOVE
Definition const.h:37
@ WHITE
Definition const.h:43
@ BLACK
Definition const.h:42
void game_export_ggf(const Game *game, FILE *f)
Write a game to the Generic Game Format (ggf) file.
Definition game.c:713
void game_import_text(Game *game, FILE *f)
Read a game from a text file.
Definition game.c:451
void game_read(Game *game, FILE *f)
Read a game from a binary file.
Definition game.c:429
int game_analyze(Game *game, Search *search, const int n_empties, const bool apply_correction)
Analyze an endgame.
Definition game.c:1532
int game_complete(Game *game, Search *search)
Terminate an unfinished game.
Definition game.c:1625
bool game_update_board(Board *board, int x)
update a board.
Definition game.c:153
void game_export_sgf(const Game *game, FILE *f)
Definition game.c:944
void wthor_to_game(const WthorGame *thor, Game *game)
convert a Wthor game to a Game.
Definition game.c:340
void game_import_ggf(Game *game, FILE *f)
Read a game from the Generic Game Format (ggf) file.
Definition game.c:582
bool game_equals(const Game *game_1, const Game *game_2)
Test if two games are equal.
Definition game.c:114
void game_import_wthor(Game *game, FILE *f)
Read a game from a Wthor file.
Definition game.c:487
void game_export_text(const Game *game, FILE *f)
Write a game to a text file.
Definition game.c:467
void game_import_pgn(Game *game, FILE *f)
Read a game from a pgn file.
Definition game.c:955
void line_to_game(const Board *initial_board, const Line *line, Game *game)
Build a game from an initial position and a move sequence.
Definition game.c:415
void game_to_wthor(const Game *game, WthorGame *thor)
convert a Game to a Whor game.
Definition game.c:366
void game_import_sgf(Game *game, FILE *f)
Read a game from a sgf file.
Definition game.c:823
void game_write(const Game *game, FILE *f)
Write a game to a binary file.
Definition game.c:440
void game_export_pgn(const Game *game, FILE *f)
Write a game to a pgn file.
Definition game.c:1203
bool game_get_board(const Game *game, const int ply, Board *board)
Get the board after 'ply' move.
Definition game.c:195
int game_score(const Game *game)
Compute the final score of the game, for the initial player.
Definition game.c:233
int move_from_wthor(int x)
Coordinates conversion from wthor to edax.
Definition game.c:38
void line_print(const Line *line, int width, const char *separator, FILE *f)
Print a move sequence.
Definition move.c:610
char * move_to_string(const int x, const int player, char *s)
Print out a move.
Definition move.c:76
void line_copy(Line *dest, const Line *src, const int from)
Copy part of a sequence to another sequence.
Definition move.c:591
Options options
Definition options.c:22
void positionhash_delete(PositionHash *hash)
Free the hash table.
Definition perft.c:724
bool positionhash_append(PositionHash *hash, const Board *b)
Append a position to the hash table.
Definition perft.c:738
void positionhash_init(PositionHash *hash, int bitsize)
Initialisation of the hash table.
Definition perft.c:709
Move generator test header file.
void * search_run(void *v)
Search the bestmove of a given board.
Definition root.c:810
void search_set_level(Search *search, const int level, const int n_empties)
Set the search level.
Definition search.c:609
void search_cleanup(Search *search)
Clean-up some search data.
Definition search.c:578
void search_set_board(Search *search, const Board *board, const int player)
Set the board to analyze.
Definition search.c:593
Game * game
Definition base.h:49
int n_games
Definition base.h:50
int size
Definition base.h:51
char move[60]
Definition game.h:33
char name[2][32]
Definition game.h:32
Board initial_board[1]
Definition game.h:23
int x
Definition move.h:22
int level
Definition options.h:40
bool pv_check
Definition options.h:72
int hash_table_size
Definition options.h:25
unsigned long long n_nodes
Definition search.h:49
int score
Definition search.h:45
long long time
Definition search.h:48
Line pv[1]
Definition search.h:47
const char * separator
Definition search.h:145
Result * result
Definition search.h:151
const char * header
Definition search.h:144
struct Search::@25 options
int verbosity
Definition search.h:142
int n_players
Definition base.h:43
WthorHeader header[1]
Definition base.h:39
WthorGame * game
Definition base.h:44
char(* tournament)[26]
Definition base.h:40
int n_tournaments
Definition base.h:41
int n_games
Definition base.h:45
char(* player)[20]
Definition base.h:42
signed char theoric_score
Definition game.h:40
char x[60]
Definition game.h:41
short tournament
Definition game.h:39
signed char score
Definition game.h:40
short white
Definition game.h:39
short black
Definition game.h:39
void time_print(long long t, bool justified, FILE *f)
Print time as "D:HH:MM:SS.CC".
Definition util.c:131
void string_to_lowercase(char *s)
Change all char of a string to lowercase.
Definition util.c:355
void path_get_dir(const char *path, char *dir)
Extract the directory of a file path.
Definition util.c:888
#define error(...)
Display an error message as "ERROR : filename : funcname : line number : ...".
Definition util.h:361
#define info(...)
Display a message.
Definition util.h:382
#define warn(...)
Display a warning message as "WARNING : ... ".
Definition util.h:373