Author: Lukas Geyer Description: Adjusted learning file locations. --- sjeng-11.2.orig/sjeng.c +++ sjeng-11.2/sjeng.c @@ -27,13 +27,18 @@ */ +#include +#include +#include +#include + #include "sjeng.h" #include "protos.h" #include "extvars.h" #include "config.h" char divider[50] = "-------------------------------------------------"; -move_s dummy = {0,0,0,0,0}; +move_s dummy = {0,0,0,0,0,0}; int board[144], moved[144], ep_square, white_to_move, comp_color, wking_loc, bking_loc, white_castled, black_castled, result, ply, pv_length[PV_BUFF], @@ -90,7 +95,7 @@ FILE *lrn_suicide; FILE *lrn_losers; -int main (int argc, char *argv[]) { +int main (void) { char input[STR_BUFF], *p, output[STR_BUFF]; char readbuff[STR_BUFF]; @@ -98,15 +103,19 @@ int depth = 4; bool force_mode, show_board; double nps, elapsed; - clock_t cpu_start, cpu_end; + clock_t cpu_start = 0, cpu_end = 0; move_s game_history[600]; move_x game_history_x[600]; - int is_edit_mode, edit_color; + int is_edit_mode, edit_color = 0; int pingnum; int braindeadinterface; int automode; rtime_t xstart_time; - + char lrn_name[STR_BUFF]; + int path_len; + struct passwd *pw; + struct stat st; + read_rcfile(); initialize_zobrist(); @@ -119,60 +128,88 @@ if (!init_book()) printf("No .OPN opening book found.\n"); - if ((lrn_standard = fopen ("standard.lrn", "rb+")) == NULL) + pw = getpwuid(getuid()); + if (pw == NULL) { + perror("Unable to get home directory"); + exit(1); + } + path_len = strlen(pw->pw_dir) + strlen("/.sjeng/"); + if (path_len + 21 >= STR_BUFF) { + fprintf(stderr,"Home directory path too long\n"); + exit(1); + } + strcpy(lrn_name, pw->pw_dir); + strcat(lrn_name, "/.sjeng/"); + + if (stat(lrn_name, &st) < 0) { + printf("Trying to create directory %s\n", lrn_name); + if (mkdir(lrn_name, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) { + perror("Unable to create directory"); + exit(1); + } + } + + strcpy(lrn_name + path_len, "standard.lrn"); + if ((lrn_standard = fopen (lrn_name, "rb+")) == NULL) { printf("No standard learn file.\n"); - if ((lrn_standard = fopen ("standard.lrn", "wb+")) == NULL) + if ((lrn_standard = fopen (lrn_name, "wb+")) == NULL) { printf("Error creating standard learn file.\n"); } else { fclose(lrn_standard); - lrn_standard = fopen ("standard.lrn", "rb+"); + lrn_standard = fopen (lrn_name, "rb+"); } } - if ((lrn_zh = fopen ("bug.lrn", "rb+")) == NULL) + + strcpy(lrn_name + path_len, "bug.lrn"); + if ((lrn_zh = fopen (lrn_name, "rb+")) == NULL) { printf("No crazyhouse learn file.\n"); - if ((lrn_zh = fopen ("bug.lrn", "wb+")) == NULL) + if ((lrn_zh = fopen (lrn_name, "wb+")) == NULL) { printf("Error creating crazyhouse learn file.\n"); } else { fclose(lrn_zh); - lrn_zh = fopen ("bug.lrn", "rb+"); + lrn_zh = fopen (lrn_name, "rb+"); } } - if ((lrn_suicide = fopen ("suicide.lrn", "rb+")) == NULL) + + strcpy(lrn_name + path_len, "suicide.lrn"); + if ((lrn_suicide = fopen (lrn_name, "rb+")) == NULL) { printf("No suicide learn file.\n"); - if ((lrn_suicide = fopen ("suicide.lrn", "wb+")) == NULL) + if ((lrn_suicide = fopen (lrn_name, "wb+")) == NULL) { printf("Error creating suicide learn file.\n"); } else { fclose(lrn_suicide); - lrn_suicide = fopen ("suicide.lrn", "rb+"); + lrn_suicide = fopen (lrn_name, "rb+"); } } - if ((lrn_losers = fopen ("losers.lrn", "rb+")) == NULL) + + strcpy(lrn_name + path_len, "losers.lrn"); + if ((lrn_losers = fopen (lrn_name, "rb+")) == NULL) { printf("No losers learn file.\n"); - if ((lrn_losers = fopen ("losers.lrn", "wb+")) == NULL) + if ((lrn_losers = fopen (lrn_name, "wb+")) == NULL) { printf("Error creating losers learn file.\n"); } else { fclose(lrn_losers); - lrn_losers = fopen ("losers.lrn", "rb+"); + lrn_losers = fopen (lrn_name, "rb+"); } } @@ -334,10 +371,10 @@ printf("Move ordering : %f%%\n", (((float)FHF*100)/(float)(FH+1))); - printf("Material score: %d Eval : %d White hand: %d Black hand : %d\n", + printf("Material score: %d Eval : %ld White hand: %d Black hand : %d\n", Material, eval(), white_hand_eval, black_hand_eval); - printf("Hash : %X HoldHash : %X\n", hash, hold_hash); + printf("Hash : %lX HoldHash : %lX\n", hash, hold_hash); /* check to see if we mate our opponent with our current move: */ if (!result) { @@ -635,7 +672,7 @@ } else if (!strcmp (input, "eval")) { check_phase(); - printf("Eval: %d\n", eval()); + printf("Eval: %ld\n", eval()); } else if (!strcmp (input, "go")) { comp_color = white_to_move; @@ -667,7 +704,7 @@ time_cushion = 0; } else if (!strncmp (input, "rating", 6)) { - sscanf (input+7, "%ld %ld", &my_rating, &opp_rating); + sscanf (input+7, "%d %d", &my_rating, &opp_rating); if (my_rating == 0) my_rating = 2000; if (opp_rating == 0) opp_rating = 2000; } @@ -729,6 +766,7 @@ printf("Move number : %d\n", move_number); if (move_number > 0) { + ply = 1; path_x[0] = game_history_x[--move_number]; unmake(&game_history[move_number], 0); reset_piece_square(); @@ -738,10 +776,12 @@ else if (!strncmp (input, "remove", 5)) { if (move_number > 1) { + ply = 1; path_x[0] = game_history_x[--move_number]; unmake(&game_history[move_number], 0); reset_piece_square(); + ply = 1; path_x[0] = game_history_x[--move_number]; unmake(&game_history[move_number], 0); reset_piece_square(); @@ -789,7 +829,7 @@ run_epd_testsuite(); } else if (!strncmp (input, "st", 2)) { - sscanf(input+3, "%d", &fixed_time); + sscanf(input+3, "%ld", &fixed_time); fixed_time = fixed_time * 100; } else if (!strncmp (input, "book", 4)) {