File: sjeng.c.patch

package info (click to toggle)
sjeng 11.2-15.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,444 kB
  • sloc: ansic: 13,378; sh: 324; makefile: 29
file content (219 lines) | stat: -rw-r--r-- 6,348 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
Author: Lukas Geyer <lukas@debian.org>
Description: Adjusted learning file locations.

--- sjeng-11.2.orig/sjeng.c
+++ sjeng-11.2/sjeng.c
@@ -27,13 +27,18 @@
 
 */
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <pwd.h>
+
 #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)) {