Keep PV in triangular array, and add multi-PV
authorH.G. Muller <h.g.muller@hccnet.nl>
Thu, 14 Jan 2010 22:18:36 +0000 (23:18 +0100)
committerH.G. Muller <h.g.muller@hccnet.nl>
Thu, 14 Jan 2010 22:18:36 +0000 (23:18 +0100)
fairymax.c

index 8b7b45a..02e3a09 100644 (file)
@@ -122,6 +122,9 @@ T[4104],                                       /* hash translation table   */
 centr[32],\r
 n[]=".*XKNBRQEWFMACHG?x+knbrqewfmachg";        /* piece symbols on printout*/\r
 \r
+int pv[10000],*sp=pv; // triangular array\r
+int margin;\r
+\r
 pboard()\r
 {int i;\r
  i=-1;W(++i<128)printf(" %c",(i&15)==BW&&(i+=15-BW)?10:n[b[i]&31]);\r
@@ -131,9 +134,10 @@ pboard()
 D(k,q,l,e,E,z,n)        /* recursive minimax search, k=moving side, n=depth*/\r
 int k,q,l,e,E,z,n;      /* (q,l)=window, e=current eval. score, E=e.p. sqr.*/\r
 {                       /* e=score, z=prev.dest; J,Z=hashkeys; return score*/\r
- int j,r,m,v,d,h,i,F,G,P,V,f=J,g=Z,C,s,flag,FF;\r
+ int j,r,m,v,d,h,i,F,G,P,V,f=J,g=Z,C,s,flag,FF,*ps=sp;\r
  signed char t,p,u,x,y,X,Y,H,B;\r
  struct _*a=A+(J+(k+S)*E&U-1);                 /* lookup pos. in hash table*/\r
+ *sp++=0;\r
  q-=q<e;l-=l<=e;                               /* adj. window: delay bonus */\r
  d=a->D;m=a->V;X=a->F;Y=a->Y;                  /* resume at stored depth   */\r
  if(a->K-Z|z&S  |                              /* miss: other pos. or empty*/\r
@@ -194,12 +198,18 @@ int k,q,l,e,E,z,n;      /* (q,l)=window, e=current eval. score, E=e.p. sqr.*/
         J+=J(0);Z+=J(4)+G-S;\r
         SHAMAX( pl[k]-=!!t; )                  /* count pieces per side    */\r
         v+=e+i;V=m>q?m:q;                      /*** new eval & alpha    ****/\r
+        if(z&S)V=m-margin>q?m-margin:q;        /* multiPV                  */\r
         C=d-1-(d>5&p>2&!t&!h);                 /* nw depth, reduce non-cpt.*/\r
         C=R<EG|P-I|d<3||t&&p-3?C:d;            /* extend 1 ply if in-check */\r
         do\r
          s=C>2|v>V?-D(16-k,-l,-V,-v,/*** futility, recursive eval. of reply */\r
                                      F,y&255,C):v;\r
         W(s>q&++C<d); v=s;                     /* no fail:re-srch unreduced*/\r
+        if(v>V&v<l){int *p=sp;\r
+         sp=ps+1;\r
+         W(*sp++=*p++);\r
+         *ps=256*x+y;\r
+        }\r
         if(z&S&&K-I)                           /* move pending: check legal*/\r
         {if(v+I&&x==K&y==L)                    /*   if move found          */\r
          {Q=-e-i;O=F;LL=L;\r
@@ -208,6 +218,7 @@ int k,q,l,e,E,z,n;      /* (q,l)=window, e=current eval. score, E=e.p. sqr.*/
           a->D=99;a->V=0;                      /* lock game in hash as draw*/\r
           R-=i/FAC;                            /*** total captd material ***/\r
           Fifty = t|p<3?0:Fifty+1;\r
+          sp=ps;\r
                      return l;}                /*   & not in check, signal */\r
          v=m;                                  /* (prevent fail-lows on    */\r
         }                                      /*   K-capt. replies)       */\r
@@ -215,7 +226,14 @@ int k,q,l,e,E,z,n;      /* (q,l)=window, e=current eval. score, E=e.p. sqr.*/
         SHAMAX( pl[k]+=!!t; )\r
         b[G]=k+6;b[FF]=b[y]=0;b[x]=u;b[H]=t;   /* undo move,G can be dummy */\r
        }                                       /*          if non-castling */\r
-       if(v>m)                                 /* new best, update max,best*/\r
+       if(z&S&&Post&v>V&v<l){int *p=ps;char X,Y;\r
+        printf("%2d ",d-2);\r
+        printf("%6d ",v);\r
+        printf("%8d %10d",(GetTickCount()-Ticks)/10,N);\r
+        while(*p){X=*p>>8;Y=*p++;\r
+        printf(" %c%c%c%c",'a'+(X&15),'8'-(X>>4),'a'+(Y&15),'8'-(Y>>4&7));}\r
+        printf("\n");fflush(stdout);\r
+       }       if(v>m)                                 /* new best, update max,best*/\r
         m=v,X=x,Y=y|S&F;                       /* mark non-double with S   */\r
        if(h){h=0;goto A;}                      /* redo after doing old best*/\r
       }\r
@@ -237,13 +255,9 @@ C:FMAX( m=m+I|P==I?m:(X=Y=0); )                /* if stalemate, draw-score */
   if(a->D<99)                                  /* protect game history     */\r
    a->K=Z,a->V=m,a->D=d,a->X=X,                /* always store in hash tab */\r
    a->F=8*(m>q)|S*(m<l),a->Y=Y;                /* move, type (bound/exact),*/\r
-  if(z&S&&Post){\r
-    printf("%2d ",d-2);\r
-    printf("%6d ",m);\r
-    printf("%8d %10d %c%c%c%c\n",(GetTickCount()-Ticks)/10,N,\r
-       'a'+(X&15),'8'-(X>>4),'a'+(Y&15),'8'-(Y>>4&7)),fflush(stdout);\r
- }}                                            /*    encoded in X S,8 bits */\r
+  }                                            /*    encoded in X S,8 bits */\r
 if(z&4*S)K=X,L=Y&~S;\r
+ sp=ps;\r
  return m+=m<e;                                /* delayed-loss bonus       */\r
 }\r
 \r
@@ -393,6 +407,7 @@ void PrintOptions()
        printf("feature option=\"Resign -check %d\"\n", Resign);\r
        printf("feature option=\"Resign Threshold -spin %d 200 1200\"\n", Threshold);\r
        printf("feature option=\"Ini File -file %s\"\n", inifile);\r
+       printf("feature option=\"MultiVariation Margin -spin %d 0 1000\"\n", margin);\r
        printf("feature option=\"Playing Style ;-) -combo Brilliant /// *Brave /// Beautiful\"\n");\r
        printf("feature option=\"Dummy Slider Example -slider 20 0 100\"\n");\r
        printf("feature option=\"Dummy String Example -file happy birthday!\"\n");\r
@@ -667,6 +682,7 @@ int main(int argc, char **argv)
                                inifile = filename; continue;\r
                        }\r
                        if(sscanf(line+7, "Clear Hash") == 1) for(i=0; i<U; i++) A->K = 0;\r
+                       if(sscanf(line+7, "MultiVariation Margin=%d", &margin) == 1) continue;\r
                        continue;\r
                }\r
                if (!strcmp(command, "go")) {\r