TalkChess.com
Hosted by Your Move Chess & Games

Author Message
Chan Rasjid

Joined: 09 Mar 2006
Posts: 567
Location: Singapore

Post subject: Re: How to implement KPK ?    Posted: Sun May 12, 2013 10:27 pm

Finally, I am able to get my KPK routine to work just as 'perfectly' as how all other programs play the KPK endings. I am using the KPK bitbase which Gert Mueller put up in the public domain. So it seems all fine - should have no bugs. Many thanks to Gert.

It was exasperating trying to get my KPK codes to work. With bitases, it should be simple to implement the KPK routine. Basically, it is to return zero when probe to bitbase shows a draw. For a win, what I found needed is just to evaluate the distance to promotion for the pawn. The other evaluation is just that the lone king stays clear from the pawn and the promotion square. It is this simple. Yet it was not working!

What actually made it work this time around is I disabled all the lines of codes that involves fifty and repetition draws in my search functions. I think there are bugs. I have yet to examine what was wrong.

There is something that need to be noted about the KPK routine. For some 'difficult' KPK endings, it seems necessary to have the two pawn/lone king race to promotion and also the Kings' race to get near the pawn. Without these coding, the play may fail. I don't clearly know the reason yet.

My evalKPK() codes is here:
 Code: int evalkpk(const int side) {     const int pcol = !bits[0][Pawn], xpcol = pcol ^ 1;     const int pK = king[pcol], loneK = king[xpcol], p = firstone(bits[pcol][Pawn]);     const int promsq = PROMOTE_SQ(p, pcol);     int probeWk, probeBk, probeWp;     int win, index, stm;     int x, d1, d2;     /* safe capture of pawn */     if (kMap[king[side]] & bits[side ^ 1][Pawn] & ~kMap[king[side ^ 1]]) {         return (side == pcol ? 2 : -2);     }     /* pawn/loneK race to promote. */     if (!(FORWARD_ROW_BITS(p, pcol) & rMap[p]->file & bits[pcol][King])) {         /* path ahead clear */         d1 = DIST(p, promsq);         d2 = DIST(loneK, promsq) - (side ^ pcol);         if (d2 > d1) {             /* promote success */             x = v8Pawn - DIST(p, promsq);             return (side == pcol ? x : -x);         }     }     /* kings' race to protect pawn. */     d1 = DIST(p, pK);     d2 = DIST(p, loneK) - (side ^ pcol);     if (d1 <= d2 + 1); /* protect success */     else {         /* pawn lost */         x = 2 + d2;         return (side == pcol ? x : -x);     }     /* probe kpk bitbase (as white with the pawn) */     if (pcol == 0) {         /* my internal chess board square mapping is unusual, (a1, a2, a3,...) -> (0, 1, 2, ...)          * convert to mapping of bitbase */         probeWk = sqMapA1B1[pK];         probeBk = sqMapA1B1[loneK];         probeWp = sqMapA1B1[p];         stm = side;     } else {         /* flip everything  */         probeWk = 63 - sqMapA1B1[pK];         probeBk = 63 - sqMapA1B1[loneK];         probeWp = 63 - sqMapA1B1[p];         stm = side ^ 1;     }     index = 2 * ((probeBk >> 3) + 8 * probeWk + 8 * 64 * ((probeWp - 8) >> 1)) + 1 * stm;     /* probe bitbase; 1 == win, 0 == draw */     win = (bitbase[index] >> (probeBk & 7)) & 1;     if (!win) {         return (side == pcol ? 2 : -2);     }     /* Now a win. The evaluation needed is this simple! */     x = v7Pawn             - 1 * DIST(p, promsq)             + 4 * DIST(loneK, p)             + 4 * DIST(loneK, promsq);     return (side == pcol ? x : -x);

This is a difficult KPK position which requires coding for the piece races:
[D]4k3/8/8/8/K7/8/4P3/8 w - - 5 1[/D]

Best Regards,
Rasjid.
_________________
Don't believe when you're told "There's no free lunch!" There is Linux.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
Subject Author Date/Time
Chan Rasjid Thu Mar 21, 2013 3:43 am
H.G.Muller Thu Mar 21, 2013 7:46 am
Chan Rasjid Thu Mar 21, 2013 8:27 am
H.G.Muller Thu Mar 21, 2013 10:07 am
H.G.Muller Thu Mar 21, 2013 10:33 am
Chan Rasjid Thu Mar 21, 2013 6:10 pm
Don Dailey Tue Apr 02, 2013 6:56 pm
Lucas Braesch Thu Mar 21, 2013 11:03 am
H.G.Muller Thu Mar 21, 2013 11:52 am
Lucas Braesch Thu Mar 21, 2013 12:04 pm
H.G.Muller Thu Mar 21, 2013 6:36 pm
H.G.Muller Thu Mar 21, 2013 9:00 pm
Chan Rasjid Sat Mar 30, 2013 8:15 am
Evert Glebbeek Sat Mar 30, 2013 8:42 am
Sven Schüle Sat Mar 30, 2013 12:12 pm
Chan Rasjid Sat Mar 30, 2013 12:20 pm
Sven Schüle Sat Mar 30, 2013 12:42 pm
Chan Rasjid Sat Mar 30, 2013 2:03 pm
Sven Schüle Sat Mar 30, 2013 6:29 pm
Wylie Garvin Sat Mar 30, 2013 12:50 pm
Chan Rasjid Sat Mar 30, 2013 1:53 pm
Evert Glebbeek Sat Mar 30, 2013 2:03 pm
H.G.Muller Sat Mar 30, 2013 2:26 pm
Sven Schüle Sat Mar 30, 2013 6:38 pm
H.G.Muller Sat Mar 30, 2013 8:13 pm
Sven Schüle Sat Mar 30, 2013 8:58 pm
H.G.Muller Sat Mar 30, 2013 10:58 pm
Sven Schüle Sat Mar 30, 2013 11:51 pm
H.G.Muller Sun Mar 31, 2013 7:35 am
Sven Schüle Sun Mar 31, 2013 9:02 am
H.G.Muller Sun Mar 31, 2013 9:09 am
Sven Schüle Sun Mar 31, 2013 9:13 am
Steven Edwards Mon May 13, 2013 2:14 am
Don Dailey Mon May 13, 2013 2:20 am
Chan Rasjid Sat Mar 30, 2013 12:18 pm
H.G.Muller Sat Mar 30, 2013 9:08 am
Re: How to implement KPK ? Chan Rasjid Sun May 12, 2013 10:27 pm
Ronald de Man Sun May 12, 2013 11:11 pm
Chan Rasjid Mon May 13, 2013 7:39 am
Don Dailey Mon May 13, 2013 2:14 am
Steven Edwards Tue May 14, 2013 7:19 am
Chan Rasjid Tue May 14, 2013 2:45 pm
Chan Rasjid Tue May 14, 2013 2:50 pm

 Jump to: Select a forum Computer Chess Club Forums----------------Computer Chess Club: General TopicsComputer Chess Club: Tournaments and MatchesComputer Chess Club: Programming and Technical DiscussionsComputer Chess Club: Engine Origins Other Forums----------------Chess Thinkers ForumChess Players ForumForum Help and Suggestions
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group
Enhanced with Moby Threads