#include #include #include #include #define MAXCOL 8 /* columns */ #define COLOURS 8 #define COLOURSHIFT 3 #define MAXPOS (1<<(COLOURSHIFT*MAXCOL)) #define MAXLOWPOS (1<<(COLOURSHIFT*HALFCOL)) #define MIN(a,b) ((a>(3*n))&7)+1; } static void printpos(Position p) { int i; for(i=0; imax ? counts[i][j] : max; } } /* length is c*m, where m ist the number of moves still necessary */ length = value/npossible+info; if (in_possible) length *= (npossible-1)/(double)npossible; /* printf("Value of %7o: %f moves, %f positions, %d max. positions\n",try,length,sumsq/npossible,max);*/ *lengthp = length/info; *posp = sumsq/npossible; *maxp = max; } static int compint(const void *p1, const void *p2) { int i1 = *(int *)p1; int i2 = *(int *)p2; if (i1 < i2) return -1; else if (i1 > i2) return 1; else return 0; } Position makemove(Position possible[], int npossible) { Position p, bestlpos, bestwavpos, bestmaxpos; int bestlpos_possible, bestwavpos_possible, bestmaxpos_possible; double length, bestlength, wavpositions, bestwavpositions; int maxpositions, bestmaxpositions; bestlength = 2*log((double)npossible); bestlpos = -1; bestlpos_possible=0; bestwavpositions = npossible+1; bestwavpos = -1; bestwavpos_possible=0; bestmaxpositions = npossible+1; bestmaxpos = -1; bestmaxpos_possible=0; for (p=0; p=0; i--) { char c = s[i]; if (c<'1' || c>('0'+COLOURS)) goto usage; code = code * COLOURS + c - '1'; } for (maxpos=1, i=0; i