19 for(i=0; i<ORDER; i++)
29 for(i=ORDER-1; i >= 0; i--)
37 eval(int *sec, int *guess, int *black, int *white)
39 int b, w, i, sc[COLORS], gc[COLORS];
42 bzero(sc, sizeof(sc));
43 bzero(gc, sizeof(gc));
44 for(i=0; i<ORDER; i++)
45 if (sec[i] == guess[i])
53 for(i=0; i<COLORS; i++)
68 for(j=0; j<ORDER; j++)
75 unsigned int i, ramax, RMX;
78 ramax = RMX - (RMX % sz);
98 for(i=0; i<ORDER; i++)
111 secret = xrand(states);
121 pl_eval(int *guess, int *b, int *w)
123 eval(sec, guess, b, w);
134 pl_eval(int *guess, int *b, int *w)
144 reduce(int *gue, int b0, int w0)
146 int i,b,w,z[ORDER],c=0;
148 for(i=0; i<states; i++)
152 eval(z, gue, &b, &w);
153 if (b != b0 || w != w0)
160 puts("THIS CANNOT HAPPEN!");
183 int cc[ORDER+1][ORDER+1], g[ORDER];
185 bzero(cc, sizeof(cc));
186 for(i=0; i<states; i++)
193 for(b=0; b<=ORDER; b++)
194 for(w=0; w<=ORDER; w++)
203 int shot[SHOTS], badness[SHOTS], i, z[ORDER], sz, whe, besti, best, worsti;
206 for(i=0; i<states; i++)
220 for(i=0; i<SHOTS; i++)
224 badness[i] = howbad(z);
227 // printf(" (%d/%d)\n", badness[i], sz);
228 if (badness[i] < besti)
233 if (badness[i] > worsti)
236 // printf("Best: %d (%d)\n", best, besti);
237 printf("(%7d-%7d/%7d) ", worsti, besti, sz);
244 int i,gue[ORDER],round,b,w,wc=0,N=0,sum=0;
247 for(i=0; i<ORDER; i++)
249 printf("%d positions, %d colors, %d states\n", ORDER, COLORS, states);
250 flags = malloc(sizeof(char) * states);
255 bzero(flags, sizeof(char) * states);
261 printf("Q%d:", ++round);
264 pl_eval(gue, &b, &w);
265 printf(" -> %d/%d -> %d states\n", b, w, reduce(gue,b,w));
272 printf("--- DONE --- (try=%d, worst case=%d, avg=%d) ---\n", N, wc, (sum+N-1)/N);