Rev 33 | Rev 154 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 33 | Rev 108 | ||
---|---|---|---|
Line 41... | Line 41... | ||
41 | * later in this file). * |
41 | * later in this file). * |
42 | * * |
42 | * * |
43 | ******************************************************************************* |
43 | ******************************************************************************* |
44 | */ |
44 | */ |
45 | void LearnBook() { |
45 | void LearnBook() { |
- | 46 | float book_learn[64], t_learn_value; |
|
46 | int nplies = 0, thisply = 0; |
47 | int nplies = 0, thisply = 0, i, j, v, cluster; |
47 | unsigned char buf32[4]; |
48 | unsigned char buf32[4]; |
48 | int i, j, cluster; |
- | |
49 | float book_learn[64], t_learn_value; |
- | |
50 | 49 | ||
51 | /* |
50 | /* |
52 | ************************************************************ |
51 | ************************************************************ |
53 | * * |
52 | * * |
54 | * If we have not been "out of book" for N moves, all we * |
53 | * If we have not been "out of book" for N moves, all we * |
55 | * we need to do is take the search evaluation for the * |
54 | * we need to do is take the search evaluation for the * |
56 | * search just completed and tuck it away in the book * |
55 | * search just completed and tuck it away in the book * |
57 | * learning array (book_learn_eval[]) for use later. * |
56 | * learning array (book_learn_eval[]) for use later. * |
58 | * * |
57 | * * |
59 | ************************************************************ |
58 | ************************************************************ |
60 | */ |
59 | */ |
61 | if (!book_file) |
60 | if (!book_file) |
62 | return; |
61 | return; |
63 | if (!learn) |
62 | if (!learn) |
64 | return; |
63 | return; |
65 | if (Abs(learn_value) != learning) |
64 | if (Abs(learn_value) != learning) |
66 | learn_value = LearnAdjust(learn_value); |
65 | learn_value = LearnAdjust(learn_value); |
67 | learn = 0; |
66 | learn = 0; |
68 | Print( |
67 | Print(32, "LearnBook() updating book database\n"); |
69 | /* |
68 | /* |
70 | ************************************************************ |
69 | ************************************************************ |
71 | * * |
70 | * * |
72 | * Now we build a vector of book learning results. We * |
71 | * Now we build a vector of book learning results. We * |
73 | * give every book move below the last point where there * |
72 | * give every book move below the last point where there * |
74 | * were alternatives 100% of the learned score. We give * |
73 | * were alternatives 100% of the learned score. We give * |
75 | * the book move played at that point 100% of the learned * |
74 | * the book move played at that point 100% of the learned * |
76 | * score as well. Then we divide the learned score by the * |
75 | * score as well. Then we divide the learned score by the * |
77 | * number of alternatives, and propagate this score back * |
76 | * number of alternatives, and propagate this score back * |
78 | * until there was another alternative, where we do this * |
77 | * until there was another alternative, where we do this * |
79 | * again and again until we reach the top of the book * |
78 | * again and again until we reach the top of the book * |
80 | * tree. * |
79 | * tree. * |
81 | * * |
80 | * * |
82 | ************************************************************ |
81 | ************************************************************ |
83 | */ |
82 | */ |
84 | t_learn_value = ((float) learn_value) / 100.0f; // Pierre-Marie Baty -- added |
83 | t_learn_value = ((float) learn_value) / 100.0f; // Pierre-Marie Baty -- added type cast |
85 | for (i = 0; i < 64; i++) |
84 | for (i = 0; i < 64; i++) |
86 | if (learn_nmoves[i] > 1) |
85 | if (learn_nmoves[i] > 1) |
87 | nplies++; |
86 | nplies++; |
88 | nplies = Max(nplies, 1); |
87 | nplies = Max(nplies, 1); |
89 | for (i = 0; i < 64; i++) { |
88 | for (i = 0; i < 64; i++) { |
90 | if (learn_nmoves[i] > 1) |
89 | if (learn_nmoves[i] > 1) |
91 | thisply++; |
90 | thisply++; |
92 | book_learn[i] = t_learn_value * (float) thisply / (float) nplies; |
91 | book_learn[i] = t_learn_value * (float) thisply / (float) nplies; |
93 | } |
92 | } |
94 | /* |
93 | /* |
95 | ************************************************************ |
94 | ************************************************************ |
96 | * * |
95 | * * |
97 | * Now find the appropriate cluster, find the key we were * |
96 | * Now find the appropriate cluster, find the key we were * |
98 | * passed, and update the resulting learn value. * |
97 | * passed, and update the resulting learn value. * |
99 | * * |
98 | * * |
100 | ************************************************************ |
99 | ************************************************************ |
101 | */ |
100 | */ |
102 | for (i = 0; i < 64 && learn_seekto[i]; i++) { |
101 | for (i = 0; i < 64 && learn_seekto[i]; i++) { |
103 | if (learn_seekto[i] > 0) { |
102 | if (learn_seekto[i] > 0) { |
104 | fseek(book_file, learn_seekto[i], SEEK_SET); |
103 | fseek(book_file, learn_seekto[i], SEEK_SET); |
105 | fread(buf32, 4, 1, book_file); |
104 | v = fread(buf32, 4, 1, book_file); |
- | 105 | if (v <= 0) |
|
- | 106 | perror("Learn() fread error: "); |
|
106 | cluster = BookIn32(buf32); |
107 | cluster = BookIn32(buf32); |
- | 108 | if (cluster) |
|
107 | BookClusterIn(book_file, cluster, book_buffer); |
109 | BookClusterIn(book_file, cluster, book_buffer); |
108 | for (j = 0; j < cluster; j++) |
110 | for (j = 0; j < cluster; j++) |
109 | if (!(learn_key[i] ^ book_buffer[j].position)) |
111 | if (!(learn_key[i] ^ book_buffer[j].position)) |
110 | break; |
112 | break; |
111 | if (j >= cluster) |
113 | if (j >= cluster) |
112 | return; |
114 | return; |
113 | if (fabs(book_buffer[j].learn) < 0.0001) |
115 | if (fabs(book_buffer[j].learn) < 0.0001) |
114 | book_buffer[j].learn = book_learn[i]; |
116 | book_buffer[j].learn = book_learn[i]; |
115 | else |
117 | else |
116 | book_buffer[j].learn = (book_buffer[j].learn + book_learn[i]) / 2.0f; // Pierre-Marie Baty -- added |
118 | book_buffer[j].learn = (book_buffer[j].learn + book_learn[i]) / 2.0f; // Pierre-Marie Baty -- added type cast |
117 | fseek(book_file, learn_seekto[i] + 4, SEEK_SET); |
119 | fseek(book_file, learn_seekto[i] + 4, SEEK_SET); |
- | 120 | if (cluster) |
|
118 | BookClusterOut(book_file, cluster, book_buffer); |
121 | BookClusterOut(book_file, cluster, book_buffer); |
119 | fflush(book_file); |
122 | fflush(book_file); |
120 | } |
123 | } |
121 | } |
124 | } |
122 | } |
125 | } |
123 | 126 | ||
Line 134... | Line 137... | ||
134 | * * |
137 | * * |
135 | ******************************************************************************* |
138 | ******************************************************************************* |
136 | */ |
139 | */ |
137 | int LearnFunction(int sv, int search_depth, int rating_difference, |
140 | int LearnFunction(int sv, int search_depth, int rating_difference, |
138 | int trusted_value) { |
141 | int trusted_value) { |
- | 142 | float multiplier; |
|
139 | static const float rating_mult_t[11] = { .00625f, .0125f, .025f, .05f, .075f, .1f, |
143 | static const float rating_mult_t[11] = { .00625f, .0125f, .025f, .05f, .075f, .1f, |
140 | 0.15f, 0.2f, 0.25f, 0.3f, 0.35f // Pierre-Marie Baty -- added |
144 | 0.15f, 0.2f, 0.25f, 0.3f, 0.35f // Pierre-Marie Baty -- added type casts |
141 | }; |
145 | }; |
142 | static const float rating_mult_ut[11] = { .25f, .2f, .15f, .1f, .05f, .025f, .012f, |
146 | static const float rating_mult_ut[11] = { .25f, .2f, .15f, .1f, .05f, .025f, .012f, |
143 | .006f, .003f, .001f // Pierre-Marie Baty -- added |
147 | .006f, .003f, .001f // Pierre-Marie Baty -- added type casts |
144 | }; |
148 | }; |
145 | float multiplier; |
- | |
146 | int sd, rd, value; |
149 | int sd, rd, value; |
147 | 150 | ||
148 | sd = Max(Min(search_depth - 10, 19), 0); |
151 | sd = Max(Min(search_depth - 10, 19), 0); |
149 | rd = Max(Min(rating_difference / 200, 5), -5) + 5; |
152 | rd = Max(Min(rating_difference / 200, 5), -5) + 5; |
150 | if (trusted_value) |
153 | if (trusted_value) |
Line 185... | Line 188... | ||
185 | * so that this move will be favored the next time the game is played. * |
188 | * so that this move will be favored the next time the game is played. * |
186 | * * |
189 | * * |
187 | ******************************************************************************* |
190 | ******************************************************************************* |
188 | */ |
191 | */ |
189 | void LearnValue(int search_value, int search_depth) { |
192 | void LearnValue(int search_value, int search_depth) { |
190 | int i; |
- | |
191 | int interval; |
193 | int i, interval; |
192 | int best_eval = -999999, best_eval_p = 0; |
194 | int best_eval = -999999, best_eval_p = 0; |
193 | int worst_eval = 999999, worst_eval_p = 0; |
195 | int worst_eval = 999999, worst_eval_p = 0; |
194 | int best_after_worst_eval = -999999, worst_after_best_eval = 999999; |
196 | int best_after_worst_eval = -999999, worst_after_best_eval = 999999; |
195 | 197 | ||
196 | /* |
198 | /* |