Chess variant : Makruk/Cambodian chess

Discussions about Winboard/Xboard. News about engines or programs to use with these GUIs (e.g. tournament managers or adapters) belong in this sub forum.

Moderator: Andres Valverde

Re: Chess variant : Makruk/Cambodian chess

Postby pcst007 » 16 Oct 2013, 09:05

Hello H.G.Muller I would like to ask you about Makruk variant Winboard. Your program works very good but when it have 3 queen on board it can't checkmate another opponent can you make it perfect. Or Knight with two Queen in the same square it can't make another opponent checkmate. I also edit your source code to Thaichess and I write some more source code but it still can make 3 queen to checkmate but improve a little bit(I mean sometime programe can check mate by themself) . So I like to know if Winboard makruk can make a book for makruk variant or not if you can make book for makruk variant I think program will perfect. and I also like to know your email address that I can send my source code of makruk for you to help me improve winboard makruk better than now. If you read this message please contact me. I hope we can improve makruk better thanks a lot for reading.
pcst007
 
Posts: 2
Joined: 16 Oct 2013, 08:28

Re: Chess variant : Makruk/Cambodian chess

Postby H.G.Muller » 17 Oct 2013, 11:20

The problem of checkmating 3 Queens is that Queens and Kings all get the same bonus for being in the center, and moving 3 Queens towards the edge to trap a single King there is no longer considered an advantage. This can be solved by multiplying the bonus for the bare King by 5, so that it becomes much more important for the strong side to to drive the bare King into a corner, than it is to keep its own pieces in the center.

For this we can activate some ShaMax code, to count how many pieces each side still has. (ShaMax needed to know that for the Shatranj baring rule.) With the following modification Fairy-Max had no problem to checkmate with 3 Queens, even when playing 40 moves/10 sec against an opponent playing 40 moves / 5 min. It took about 30 moves.

Code: Select all
       {v=gt=0;G:                              /* retry move with gating   */
        v+=centr[p]?b[x+257]-b[y+257]:0;       /* center positional pts.   */
        if(pl[16-k]==1)v*=5;                   /* drive bare king to corner **********************/
        if(!(G&S))b[FF]=b[G],v+=50;            /* castling: put R & score  */
        b[G]=b[H]=0;b[x]=gt;b[y]=u|32;         /* do move, set non-virgin  */
        pl[t&31]-=!!t;                         /* updat victim piece count */
        v-=w[p]>0|R<EG?0:20;                   /*** freeze K in mid-game ***/
        if(p<3)                                /* pawns:                   */
        {v-=9*((x-2&M||b[x-2]-u)+              /* structure, undefended    */
               (x+2&M||b[x+2]-u)               /*        squares plus bias */
              +(w[b[x^16]&15]<0))              /*** cling to magnetic K ***/
              +(R-76>>2);                      /* end-game Pawn-push bonus */
         b[y]+=V=y+r+1&S?647-p|pm:2*(u&y+16&32);/*upgrade P or convert to Q*/
         if(V&makruk)b[y]=u|7,V=480;           /* Makruk promotion on 6th  */
         V>>=sh;                               /* for Shatranj promo to F  */
         i+=V;                                 /* promotion / passer bonus */
        } if(z&S && GamePtr<6) v+=(rand()>>10&31)-16;
        J+=J(0);Z+=J(4)+G-S;
        pl[k]-=!!t;                            /* count pieces per side    ****************/
        v+=e+i;V=m>q?m:q;                      /*** new eval & alpha    ****/
        if(z&S)V=m-margin>q?m-margin:q;        /* multiPV                  */
        C=d-1-(d>5&p>2&!t&!h);                 /* nw depth, reduce non-cpt.*/
        C=R<EG|P-I|d<3||t&&w[p]>0?C:d;         /* extend 1 ply if in-check */
        do
         s=C>2|v>V?-D(16-k,-l,-V,-v,/*** futility, recursive eval. of reply */
                                     F,y&255,C):v;
        W(s>q&++C<d); v=s;                     /* no fail:re-srch unreduced*/
        if(v>V&v<l){int *p=sp;
         sp=ps+1;
         W(*sp++=*p++);
         *ps=256*x+y;
        }
        if(z&S&&K-I)                           /* move pending: check legal*/
        {if(v+I&&x==K&y==L&gt==GT)             /*   if move found          */
         {Q=-e-i;O=F;LL=L;prom=gt;
          if(b[y]-u&15)prom=b[y]-=PromPiece,   /* (under-)promotion:       */
           Q-=abs(w[prom&=15])-w[p]-(6*S>>sh), /*  correct piece & score & */
                       Z+=PromPiece;           /*  invalidate hash         */
          a->D=99;a->V=0;                      /* lock game in hash as draw*/
          R-=i/FAC;                            /*** total captd material ***/
          Fifty = t|p<3?0:Fifty+1;
          sp=ps;
                     return l;}                /*   & not in check, signal */
         v=m;                                  /* (prevent fail-lows on    */
        }                                      /*   K-capt. replies)       */
        pl[k]+=!!t; pl[t&31]+=!!t;       /*******************************************/
        b[G]=b[FF];b[FF]=b[y]=0;b[x]=u;b[H]=t; /* undo move,G can be dummy */
       }                                       /*          if non-castling */

(The 3 modified lines are highlighted with *****.)

With two (like) Q plus N it is more difficult, as apparently the mate is only possible in the corner of the color of the Q. So it allows the bare King to seek shelter in the safe corner, even with this modification. The same problem exists in Chess with KBNK. I could cure it by adding a term to the edge/corner penalty that breaks the symmetry of the corners, in the InitGame routine:

Code: Select all
  L=8;W(L--)b[16*L+K+257]=(K-BW/2)*(K-BW/2)+(L-3.5)*(L-3.5)-1.3*(L-3.5)*(K-BW/2); /* center-pts table   */


The third term has opposite sign in colors of different color, and here is chosen to attaract the bare King to the light corners, so that the strong side will try to drive it to the dark corner. Indeed this works well: with two dark Q + N it now has no difficulty checkmating, at 40 moves/min.

But this cannot be a solution, as the extra term wrecks middle-game play, and the sign should furthermore depend on the color of the Q. It could be solved by adding code in the main program to check for this end-game by counting the pieces on the board, and determining the color of the Q, and only then adapt the table.

As to an opening book:

I don't play Makruk myself, so I have no idea what moves are strategically good or bad. I also have no games available played by strong Makruk players. (Not even a single one!) So I cannot make an opening book, simply because I have no idea what to put in it. Someone that knows how to play Makruk should make that.

With WinBoard you can easily make a book by hand: Just copy the file 'empty_book.bin' that is supplied with WinBoard to (say) makruk_book.bin, and install that as GUI book in WinBoard in the Common Engine Options dialog. Then you can use the Edit Book dialog to add moves to the book. Just write a weight (a number to indicate the relative playing frequency) and a move for the current position, and press OK, and WinBoard will add it to the book.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Chess variant : Makruk/Cambodian chess

Postby H.G.Muller » 18 Oct 2013, 18:23

Knight + 2 Med is actually a very nasty end-game. Even when the Meds are on different colors, Faity-Max has problems with it, and cannot do it at 40 moves/10 sec against a better opponent. The problem is that a Knight on d6 (quite close to the center) and a Med on b6 together are already enoughto trap the bare King on a8-b8. So when Fairy-Max does not have enough search depth to actually see the checkmate when the King and other Med are in the center (and at 0.25 sec/move it does not have that), it sees no reason to march these pieces from their 'optimal' place in the center towards the King.

So it is really essential that the strong side uses a centralization table (Fairy-Max' idea of a piece-square table, but shared by all pieces) which is not static, but depends on the actual position of the bare King.

[Edit]
OK, I think I have a reasonable solution. At 40 moves/10 sec it now usually wins with K+3M and K+N+2M (both like and unlike) against an opponent that thinks 30 times longer. And with longer thinking time it hardly ever messes up. The way I do it is by altering the centralization table before the search starts, and actually use separate tables for the bare king and for the other pieces. To this end I declared the global array b[] (that holds both board and centralzation table) somewhat bigger (769 elements in stead of 513), and fill the last section with the PST for the bare King. The code to update the evaluation then becomes With a new local variable int pst):

Code: Select all
        pst=k+16&bare?513:257;
        v+=centr[p]?b[x+pst]-b[y+pst]:0;       /* center positional pts.   */

which desides which table to use depending on whether the currend side to move k matches a new global variable int bare. To set bare (which is cleared in InitGame) and the tables I use a new routine

Code: Select all
void Mating()
{
 char p,w,S,x,y;
 w=N=0;
 K=BW;W(K--)
 {L=8;W(L--)p=b[16*L+K],N+=!!p,w+=p&16;} /* count total and white pieces   */
 if(w==16)bare=32;if(16*N-w==16)bare=16; /* order multiplying center score of bare King */
 if(bare&&N==5){ /* can be KNFFK */
  N=S=0,w=-1;
  K=BW;W(K--)
  {L=8;W(L--){p=b[16*L+K];if(p&&p==bare+19)x=K,y=L;p&=15,N+=p==11,S+=p==7,w+=(p==7)&(L^K);}} /* count Knights and Ferzes */
  w=(N&S==2)*w; /* if exactly 1 N and 2 F, set w = +1 or -1 depending on color of F, 0 otherwise */
  K=BW;W(K--)
  {L=8;W(L--)b[16*L+K+257]=(K-BW/2)*(K-BW/2)+(L-3.5)*(L-3.5)+(x-K)*(x-K)+(y-L)*(y-L), /* center-pts table   */
             b[16*L+K+513]=(4-2*w*w)*((K-BW/2)*(K-BW/2)+(L-3.5)*(L-3.5)-2*w*(L-3.5)*(K-BW/2)); /* bare-king table */
 }}
}

This first checks the board to see if there is a bare King, and for which side, and if there is it sets bare to the value corresponding to the side. It then scans the board to find the location of the bare King (x,y), and to count the number of Knights and Mets, and the sum of the colors of the later. If they are the same color, (sum w is 0 or 2), then the corners are not equivalent, and the PST for the bare King will get an extra term to give a larger penalty for the bare King in the corner of the color of the Mets. Based on the position of the bare King, the centralization table for the attacking pieces now gets an extra penalty proportional to the square of the distance to that King.

This routine is done before every search; in main() I have:
Code: Select all
                        Mating();
                        N=0;K=I;
                        if (D(Side,-I,I,Q,O,LL|S,3)==I) {
 

This together seems to be enough. I am starting to doubt now, though, that with K + 2 like M you can only mate in one corner; At longer thinking time I sometimes see it announce a pretty long mate in the 'wrong' corner too. It seems to be more difficult in that corner, though; at short thinking time it could never find the mate there.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Chess variant : Makruk/Cambodian chess

Postby pcst007 » 21 Oct 2013, 00:50

Thanks you for modify winboard Makruk again I will try you new code. And learn more about winboard. And I try already it better than before Excellent Good job. Thanks for you help. :D :D :idea:
pcst007
 
Posts: 2
Joined: 16 Oct 2013, 08:28

Previous

Return to Winboard and related Topics

Who is online

Users browsing this forum: No registered users and 32 guests