ChessUSA.com TalkChess.com
Hosted by Your Move Chess & Games
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to implement KPK ?
Goto page 1, 2, 3, 4, 5  Next
 
Post new topic       TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions Threaded
View previous topic :: View next topic  
Author Message
Chan Rasjid



Joined: 09 Mar 2006
Posts: 567
Location: Singapore

PostPosted: Thu Mar 21, 2013 3:43 am    Post subject: How to implement KPK ? Reply to topic Reply with quote

Hello,

I have implemented a KPK algorithm based on what is found in the chess programming wiki. But it does not seem to work. There is a possibility the problem may not be the algorithm itself, but that my search has some subtle bugs somewhere.

From the wiki (excluding some exceptions for the pawn in files ABGH), the draws:
1) the pawn may be safely captured.
2) the lone king fronts the pawn, etc...
3) the kings in direct opposition, etc...
kpk()return score 0/1 on draw.

I think the wiki has an error as it seems to indicate an additional condition for 1) and 2)
to exclude positions where the lone king is at the last rank (should be stalemate).

The won positions:
1) when the pawn wins in a race with the lone king to the promotion square. The path of the pawn clear of its king.
2) when the pawn's king defends the stop(front square) and telestops(all squares ahead of the stop) of the pawn including the promote square from 1-3 squares.
kpk() return 8xPawn less distance to promote.

When neither drawn or won kpk() return 5xPawn and some simple evaluation terms.

My understanding is that such an implementation should be able to deal with the KPK endings without failing. Or is there something missing?

The following is my implementation. kMap[] is the attack bitboard of the king.
Code:

static int evalkpk(const int side) {
    const int xside = side ^ 1;
    const int pCol = !bits[0][Pawn];
    const int xpCol = pCol ^ 1;
    const int P = pclist[pCol][Pawn][0].sq;
    const int pK = king[pCol], loneK = king[xpCol];
    const int promSq = PROMOTE_SQ(P, pCol);
    const int pFrontSq = pCol ? P - 1 : P + 1;
    const int pBackSq = pCol ? P + 1 : P - 1;
    const int pFrontFrontSq = pFrontSq != promSq ? (pCol ? pFrontSq - 1 : pFrontSq + 1) : -1;
    const int pOnMove = (pCol == side);
    int x, y;

    if ((kMap[king[side]] & bits[xside][Pawn] & ~kMap[king[xside]])) {
        /* pawn safely captured */
        return 1;
    }

    /* loneK front P; stalemate when loneK at last rank  */
    if (loneK == pFrontSq) {
        if (pK == pBackSq && !pOnMove) {
            return 1;
        }
        /* pK diagonal behind P */
        if ((pCol ? pAttack[P]->w & BB(pK) : pAttack[P]->b & BB(pK)) && pOnMove) {
            return 1;
        }
    }

    /**Kings stand in the vertical opposition and the pawn is on the right/left side of the king of the
     * stronger side which is about to move.
     * stalemate when loneK at last rank
     */
    if ((pCol ? loneK == pK - 2 : loneK == pK + 2)
            && kMap[pK] & rMap[pK]->rank & BB(P) && pOnMove) {
        return 1;
    }

    /* Won :- pK defends all squares ahead P upto to 3 */
    if (kMap[pK] & BB(pFrontSq)) {
        x = v8Pawn - DIST(P, promSq);
        if (promSq == pFrontSq) {
            return (pOnMove ? x : -x);
        }
        if (kMap[pK] & BB(pFrontFrontSq)) {
            if (promSq == pFrontFrontSq) {
                return (pOnMove ? x : -x);
            }

            if (kMap[pK] & BB(pCol ? pFrontFrontSq - 1 : pFrontFrontSq + 1)) {
                return (pOnMove ? x : -x);
            }
        }
    }

    /* P wins in race to promote.
        P path ahead clear of pawn king */
    if (!((pCol ? BB(P) - 1 : ~(BB(P) - 1)) & rMap[P]->file & BB(pK))) {
        x = DIST(P, promSq);
        y = DIST(loneK, promSq) - !pOnMove;
        if (y > x) {
            x = v8Pawn - DIST(P, promSq);
            return (pOnMove ? x : -x);
        }
    }

    /* NOT SURE THIS IS OK ?
     * P race to promote fails and  if pawn K lost in K-K race to protect P, draws.
     * P on move
     * */
    x = DIST(pK, P);
    y = DIST(loneK, P) - !pOnMove;
    if (x <= y + 1) {
        /* pawn king wins; P now safe; */
        ;
    } else {
        /* P fails to promote; pawn king fails to protect pawn;
         * draw
         *   */
        return 1;
    }

    x = v5Pawn
            - DIST(P, promSq) * 10
            - DIST(pK, P) * 5
            + DIST(loneK, P) * 5
            - DIST(pK, promSq) * 2
            + DIST(loneK, promSq) * 2
            - (loneK == pFrontSq || loneK == pFrontFrontSq) * 10
            - ((pCol ? loneK == pK - 2 : loneK == pK + 2)) * 10; /* kings in opposition */

    return (pOnMove ? x : -x);
}



Best Regards,
Rasjid.
_________________
Don't believe when you're told "There's no free lunch!" There is Linux.
Back to top
View user's profile Send private message
H.G.Muller



Joined: 10 Mar 2006
Posts: 20720
Location: Amsterdam

PostPosted: Thu Mar 21, 2013 7:46 am    Post subject: Re: How to implement KPK ? Reply to topic Reply with quote

Why not just use the bitbase? It is only 64KB.
Back to top
View user's profile Send private message Visit poster's website
Chan Rasjid



Joined: 09 Mar 2006
Posts: 567
Location: Singapore

PostPosted: Thu Mar 21, 2013 8:27 am    Post subject: Re: How to implement KPK ? Reply to topic Reply with quote

hgm wrote:
Why not just use the bitbase? It is only 64KB.

Because there is no free lunch Very Happy

Though magic bitboard move generation should be the best, there is no codes that is in the public domain. I am still using my rotated birboard.

Same for bitbase.

Rasjid.
_________________
Don't believe when you're told "There's no free lunch!" There is Linux.
Back to top
View user's profile Send private message
H.G.Muller



Joined: 10 Mar 2006
Posts: 20720
Location: Amsterdam

PostPosted: Thu Mar 21, 2013 10:07 am    Post subject: Re: How to implement KPK ? Reply to topic Reply with quote

You could write your own code to generate it, and put it in the public domain. Idea

That seems simpler, and much less bug-prone then the code you are trying to write now.

Let me make a first attempt. (Completely untested...)

Code:
/* Public-domain KPK bitbase code by H.G. Muller */

#define WTM 0
#define BTM 1

char dtc[2][64][64][64]; // 512 KB
char bitbase[2*62*64*6];

char steps[] = {1, -1, 16, -16, 15, -15, 17, -17};
void
Init ()
{
  int wk, bk, p;
  for(wk=0; wk<64; wk++) for(bk=0; bk<64; bk++) for(p=0; p<64; p++) {
    if(bk == wk) dtc[BTM][wk][p][bk] = 1, dtc[WTM][wk][p][bk] = -1; else
    if(wk == p) dtc[BTM][wk][p][bk] = dtc[WTM][wk][p][bk] = -1; else
    if(bk ==  p) dtc[BTM][wk][p][bk] = 1; else // with WTM black just captured P
    if(p >= 56) dtc[WTM][wk][p][bk] = 1; // promoted and on move = win
  }
}

void
BlackPass ()
{
  int wk, bk, p, d;
  for(wk=0; wk<64; wk++) for(bk=0; bk<64; bk++) for(p=0; p<64; p++) {
    int O88 = (bk & 070) + bk; // 0x88 square number
    if(dtc[BTM][wk][p][bk]) continue; // already decided
    dtc[BTM][wk][p][bk] = 1; // assume lost, if no escape will be found
    for(d=0; d<8; d++) {
      int to = O88 + steps[d];
      if(to & 0x88) continue; // off board
      if(dtc[WTM][wk][p][to] <= 0) { dtc[BTM][wk][p][bk] = 0; break; } // escape
    }
  }
}

void
WhitePass ()
{
  int wk, bk, p, d;
  for(wk=0; wk<64; wk++) for(bk=0; bk<64; bk++) for(p=0; p<64; p++) {
    int O88 = (wk & 070) + wk; // 0x88 square number
    if(dtc[WTM][wk][p][bk]) continue; // already decided
    if(bk != p) { // pawn not captured, so can move
      if(p+8 != bk && dtc[BTM][wk][p+8][bk] > 0)  { dtc[WTM][wk][p][bk] = 1; continue; }
      if(p+7 == bk && (p & 7) != 0)  { dtc[WTM][wk][p][bk] = 1; continue; }
      if(p+9 == bk && (p & 7) != 7)  { dtc[WTM][wk][p][bk] = 1; continue; }
    }
    for(d=0; d<8; d++) {
      int to = O88 + steps[d];
      if(to & 0x88) continue; // off board
      if(dtc[BTM][to][p][bk] > 0) { dtc[WTM][wk][p][bk] = 1; break; }
    }
  }
}

void
Pack ()
{
  int wk, bk, p, i;
  for(wk=0; wk<64; wk++) for(bk=0; bk<64; bk++) for(p=8; p<56; p++) {
    int index = (bk >> 3) + 8*wk + 8*64*(p-8);
    bitbase[2*index] |= (dtc[WTM][wk][p][bk] > 0) << (bk & 7);
    bitbase[2*index+1] |= (dtc[BTM][wk][p][bk] > 0) << (bk & 7);
  }
}

void
Build ()
{
  int i;
  Init();
  for(i=0; i<100; i++) // won't take more than 100 moves
    WhitePass(), BlackPass();
  Pack();
}
Back to top
View user's profile Send private message Visit poster's website
H.G.Muller



Joined: 10 Mar 2006
Posts: 20720
Location: Amsterdam

PostPosted: Thu Mar 21, 2013 10:33 am    Post subject: Re: How to implement KPK ? Reply to topic Reply with quote

The white pass and black pass look very similar, so perhaps it is more elegant to merge them into one routine:

Code:
void
Pass (int stm)
{
  int wk, bk, p, d;
  for(wk=0; wk<64; wk++) for(bk=0; bk<64; bk++) for(p=0; p<64; p++) {
    int k = stm == WTM ? wk : bk
    int O88 = (k & 070) + k; // 0x88 square number of King
    if(dtc[stm][wk][p][bk]) continue; // already decided
    dtc[stm][wk][p][bk] = stm;  // assume lost if btm, undecided if wtm
    if(bk != p && stm == WTM) { // pawn not captured, so can move
      if(p+8 != bk && dtc[BTM][wk][p+8][bk] > 0)  { dtc[WTM][wk][p][bk] = 1; continue; }
      if(p+7 == bk && (p & 7) != 0)  { dtc[WTM][wk][p][bk] = 1; continue; }
      if(p+9 == bk && (p & 7) != 7)  { dtc[WTM][wk][p][bk] = 1; continue; }
    }
    for(d=0; d<8; d++) {
      int to = O88 + steps[d];
      if(to & 0x88) continue; // off board
      if(stm == WTM ? dtc[BTM][to][p][bk] > 0 : dtc[WTM][wk][p][to] > 0)
      { dtc[stm][wk][p][bk] = !stm; break; }
    }
  }
}

void
Build ()
{
  int i;
  Init();
  for(i=0; i<100; i++) // won't take more than 100 moves
    Pass(WTM), Pass(BTM);
  Pack();
}


I guess the bk == p positions should be set to -1 in Init(), and not to 1; the Pass() code does not ever test the state of the daughter position in dtc when it captures the black King with a Pawn, but just assigns a win. So the only testing of this position that ever is important is when the black King stepped onto the Pawn, whether on the previous ply or longer before that. The btm cases have to be marked as draw, to prevent black being forced to 'step off' the Pawn again by zugzwang when white does not have a King move to capture the black King, and tries another one.
Back to top
View user's profile Send private message Visit poster's website
Lucas Braesch



Joined: 31 May 2010
Posts: 2849

PostPosted: Thu Mar 21, 2013 11:03 am    Post subject: Re: How to implement KPK ? Reply to topic Reply with quote

hgm wrote:
Why not just use the bitbase? It is only 64KB.

mine is 24 KB: 64*64*24*2 = 24576 * 8 bits = 24 KB. But it's not public domain and never will be: GPL stays GPL, that's the whole point of it.
_________________
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
Back to top
View user's profile Send private message Visit poster's website
H.G.Muller



Joined: 10 Mar 2006
Posts: 20720
Location: Amsterdam

PostPosted: Thu Mar 21, 2013 11:52 am    Post subject: Re: How to implement KPK ? Reply to topic Reply with quote

Ah, you make use of left-right symmetry. Nice idea. I now did that too, by adding a >>1 to the Pawn square during packing, and incrementing it in steps of 2. This should throw away all positions where the Pawn is on an odd file. (A bit wasteful, as the generation still uses the full set of positions, but the assumption was this would be infinitely fast anyway, or that speed would not be important because you save it on a file.)

The following code is tested in the sense that it compiles (there was a missing semicolon), and runs without segfaulting (I had forgotten to convert the 0x88 to-square back to a normal square index.)

Code:
/* Public-domain KPK bitbase code by H.G. Muller */

#define WTM 0
#define BTM 1

char dtc[2][64][64][64]; // 512 KB
char bitbase[2*64*64*3];

char steps[] = {1, -1, 16, -16, 15, -15, 17, -17};

void
Init ()
{
  int wk, bk, p;
  for(wk=0; wk<64; wk++) for(bk=0; bk<64; bk++) for(p=0; p<64; p++) {
    if(bk == wk) dtc[BTM][wk][p][bk] = 1, dtc[WTM][wk][p][bk] = -1; else
    if(wk == p) dtc[BTM][wk][p][bk] = dtc[WTM][wk][p][bk] = -1; else
    if(bk ==  p) dtc[BTM][wk][p][bk] = -1; else // with WTM black just captured P
    if(p >= 56) dtc[WTM][wk][p][bk] = 1; // promoted and on move = win
  }
}

void
Pass (int stm)
{
  int wk, bk, p, d;
  for(wk=0; wk<64; wk++) for(bk=0; bk<64; bk++) for(p=0; p<64; p++) {
    int k = stm == WTM ? wk : bk;
    int O88 = (k & 070) + k; // 0x88 square number of King
    if(dtc[stm][wk][p][bk]) continue; // already decided
    dtc[stm][wk][p][bk] = stm;  // assume lost if btm, undecided if wtm
    if(bk != p && stm == WTM) { // pawn not captured, so can move
      if(p+8 != bk && dtc[BTM][wk][p+8][bk] > 0)  { dtc[WTM][wk][p][bk] = 1; continue; }
      if(p+7 == bk && (p & 7) != 0)  { dtc[WTM][wk][p][bk] = 1; continue; }
      if(p+9 == bk && (p & 7) != 7)  { dtc[WTM][wk][p][bk] = 1; continue; }
    }
    for(d=0; d<8; d++) {
      int to = O88 + steps[d];
      if(to & 0x88) continue; // off board
      to -= to>>1 & 070;
      if(stm == WTM ? dtc[BTM][to][p][bk] > 0 : dtc[WTM][wk][p][to] > 0)
      { dtc[stm][wk][p][bk] = !stm; break; }
    }
  }
}

void
Pack ()
{
  int wk, bk, p, i;
  for(wk=0; wk<64; wk++) for(bk=0; bk<64; bk++) for(p=8; p<56; p+=2) {
    int index = (bk >> 3) + 8*wk + 8*64*(p-8>>1);
    bitbase[2*index] |= (dtc[WTM][wk][p][bk] > 0) << (bk & 7);
    bitbase[2*index+1] |= (dtc[BTM][wk][p][bk] > 0) << (bk & 7);
  }
}

void
Build ()
{
  int i;
  Init();
  for(i=0; i<100; i++) // won't take more than 100 moves
    Pass(WTM), Pass(BTM);
  Pack();
}


When I run it, it prints

Code:
white to move: 211980+, 23085=, 27079-
black to move: 140386+, 113694=, 8064-


where = and - together count the non-won positions (which are not properly distinguished by the algorithm), and + the number of listed wins.

[Edit] O, I guess it still needs a stalemate correction.
Back to top
View user's profile Send private message Visit poster's website
Lucas Braesch



Joined: 31 May 2010
Posts: 2849

PostPosted: Thu Mar 21, 2013 12:04 pm    Post subject: Re: How to implement KPK ? Reply to topic Reply with quote

hgm wrote:
Ah, you make use of left-right symmetry. Nice idea.

This is no idea of mine. It's a great classic, and rather trivial. Many have done it before me. Some might have done it even before I was born Wink
_________________
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
Back to top
View user's profile Send private message Visit poster's website
Chan Rasjid



Joined: 09 Mar 2006
Posts: 567
Location: Singapore

PostPosted: Thu Mar 21, 2013 6:10 pm    Post subject: Re: How to implement KPK ? Reply to topic Reply with quote

hgm wrote:
You could write your own code to generate it, and put it in the public domain. Idea

That seems simpler, and much less bug-prone then the code you are trying to write now.

Let me make a first attempt. (Completely untested...)

Code:
/* Public-domain KPK bitbase code by H.G. Muller */

#define WTM 0
#define BTM 1

char dtc[2][64][64][64]; // 512 KB
char bitbase[2*62*64*6];

char steps[] = {1, -1, 16, -16, 15, -15, 17, -17};
void
Init ()
{
  int wk, bk, p;
  for(wk=0; wk<64; wk++) for(bk=0; bk<64; bk++) for(p=0; p<64; p++) {
    if(bk == wk) dtc[BTM][wk][p][bk] = 1, dtc[WTM][wk][p][bk] = -1; else
    if(wk == p) dtc[BTM][wk][p][bk] = dtc[WTM][wk][p][bk] = -1; else
    if(bk ==  p) dtc[BTM][wk][p][bk] = 1; else // with WTM black just captured P
    if(p >= 56) dtc[WTM][wk][p][bk] = 1; // promoted and on move = win
  }
}

void
BlackPass ()
{
  int wk, bk, p, d;
  for(wk=0; wk<64; wk++) for(bk=0; bk<64; bk++) for(p=0; p<64; p++) {
    int O88 = (bk & 070) + bk; // 0x88 square number
    if(dtc[BTM][wk][p][bk]) continue; // already decided
    dtc[BTM][wk][p][bk] = 1; // assume lost, if no escape will be found
    for(d=0; d<8; d++) {
      int to = O88 + steps[d];
      if(to & 0x88) continue; // off board
      if(dtc[WTM][wk][p][to] <= 0) { dtc[BTM][wk][p][bk] = 0; break; } // escape
    }
  }
}

void
WhitePass ()
{
  int wk, bk, p, d;
  for(wk=0; wk<64; wk++) for(bk=0; bk<64; bk++) for(p=0; p<64; p++) {
    int O88 = (wk & 070) + wk; // 0x88 square number
    if(dtc[WTM][wk][p][bk]) continue; // already decided
    if(bk != p) { // pawn not captured, so can move
      if(p+8 != bk && dtc[BTM][wk][p+8][bk] > 0)  { dtc[WTM][wk][p][bk] = 1; continue; }
      if(p+7 == bk && (p & 7) != 0)  { dtc[WTM][wk][p][bk] = 1; continue; }
      if(p+9 == bk && (p & 7) != 7)  { dtc[WTM][wk][p][bk] = 1; continue; }
    }
    for(d=0; d<8; d++) {
      int to = O88 + steps[d];
      if(to & 0x88) continue; // off board
      if(dtc[BTM][to][p][bk] > 0) { dtc[WTM][wk][p][bk] = 1; break; }
    }
  }
}

void
Pack ()
{
  int wk, bk, p, i;
  for(wk=0; wk<64; wk++) for(bk=0; bk<64; bk++) for(p=8; p<56; p++) {
    int index = (bk >> 3) + 8*wk + 8*64*(p-8);
    bitbase[2*index] |= (dtc[WTM][wk][p][bk] > 0) << (bk & 7);
    bitbase[2*index+1] |= (dtc[BTM][wk][p][bk] > 0) << (bk & 7);
  }
}

void
Build ()
{
  int i;
  Init();
  for(i=0; i<100; i++) // won't take more than 100 moves
    WhitePass(), BlackPass();
  Pack();
}


As Deng Xiaopeng said: "It does not matter if a cat is red or black as long as it catches the mouse" - but don't take too long.

As Dr. Robert Hyatt said: "In my forty years in computer chess, I have yet to see a game that played to a KPK ending." - but there is always a tomorrow.

As Herr Muller said: "I have already put the KPK bitbase generator in the public domain. If you don't understand simple retrograde analysis starting from the promotion squares and about the concept of un-make, you should not be in chess programming. Go! Join a choir and make some sound!" - don't be too certain that that someone would't be signed up by Sony later.

As another said:"If your program can't outplay Houdini 5, don't give the excuse that it is because you have no KPK bitbase or that you discovered a bug in your KPK routine. Just say - ' Robert is really a genius'"

It does not matter very much if I use the KPK bitbase. If there is a bug in my search, then it will still not be able to play a KPK ending.

Best Regards,
Rasjid.
_________________
Don't believe when you're told "There's no free lunch!" There is Linux.
Back to top
View user's profile Send private message
H.G.Muller



Joined: 10 Mar 2006
Posts: 20720
Location: Amsterdam

PostPosted: Thu Mar 21, 2013 6:36 pm    Post subject: Re: How to implement KPK ? Reply to topic Reply with quote

I see KPK quite often.

Anyway, to further the public-domain cause, the following code actually runs, and prints some numbers that seem to make sense (like the number of stalemates, which matches what I calculated by hand). I even put in the initial double-push, which is important for rule-of-squares situations.

Btw, this is the dumb algorithm, which does not use any unmoves. It just attempts regular moving from all not-yet-decided positions, to look for a move to a won position for white, and to a non-lost position for black.

Code:
/* Public-domain KPK bitbase code by H.G. Muller */

#define WTM 0
#define BTM 1

char dtc[2][64][64][64]; // 512 KB
char bitbase[2*64*64*3];

char steps[] = {1, -1, 16, -16, 15, -15, 17, -17}; // 0x88 King steps

void
Init ()
{ /* 3 = bK captured, 2 = can capture bK, 1 = won, 0 = undecided, -1 = broken or wK captured */
  int wk, bk, p;
  for(wk=0; wk<64; wk++) for(p=0; p<64; p++) for(bk=0; bk<64; bk++) {
    if(bk == wk) dtc[BTM][wk][p][bk] = 3, dtc[WTM][wk][p][bk] = -1; else
    if(wk == p) dtc[BTM][wk][p][bk] = dtc[WTM][wk][p][bk] = -1; else
    if(bk ==  p) dtc[BTM][wk][p][bk] = -3; else // with WTM black just captured P
    if(p >= 56) dtc[WTM][wk][p][bk] = 1; // promoted and on move = win
  }
}

void
Pass (int stm, int first, int def, int esc)
{
  int wk, bk, p, d;
  for(wk=0; wk<64; wk++) for(p=0; p<64; p++) for(bk=0; bk<64; bk++) {
    int k = stm == WTM ? wk : bk;
    int O88 = (k & 070) + k; // 0x88 square number of King
    if(dtc[stm][wk][p][bk]) continue; // already decided
    dtc[stm][wk][p][bk] = def;  // assume lost if btm, undecided if wtm
    if(bk != p && stm == WTM) { // pawn not captured, so can move
      if(p+8 != bk && (dtc[BTM][wk][p+8 ][bk] > first || p < 16 &&
         p+16 != bk && dtc[BTM][wk][p+16][bk] > first))  { dtc[WTM][wk][p][bk] = esc; continue; }
      if(p+7 == bk && (p & 7) != 0)  { dtc[WTM][wk][p][bk] = 2; continue; }
      if(p+9 == bk && (p & 7) != 7)  { dtc[WTM][wk][p][bk] = 2; continue; }
    }
    for(d=0; d<8; d++) {
      int to = O88 + steps[d];
      if(to & 0x88) continue; // off board
      to -= to>>1 & 070;
      if(stm == WTM ? dtc[BTM][to][p][bk] > first : dtc[WTM][wk][p][to] <= first)
      { dtc[stm][wk][p][bk] = esc; break; }
    }
  }
}

void
Pack ()
{
  int wk, bk, p, i;
  for(wk=0; wk<64; wk++) for(p=8; p<56; p+=2) for(bk=0; bk<64; bk++) { // calculate probe address and bit
    int index = (bk >> 3) + 8*wk + 8*64*(p-8>>1);
    bitbase[2*index] |= (dtc[WTM][wk][p][bk] > 0) << (bk & 7);
    bitbase[2*index+1] |= (dtc[BTM][wk][p][bk] > 0) << (bk & 7);
  }
}

void
Build ()
{
  int i;
  Init();
  Pass(WTM, 2, 0, 2); Pass(BTM, 1, -2, 0); // calculate King captures and

stalemates
  for(i=0; i<25; i++) // won't take more than 25 moves
    Pass(WTM, 0, 0, 1), Pass(BTM, 0, 1, 0);
  Pack();
}


Printing the stats of the positions with the Pawn on rank 2-7 afterwards gives:

Code:
white to move: 124960+, 41044=, 6096-, 0 stalemate, 24508 K-capture
black to move: 97604+, 89866=, 6066-, 18 stalemate, 0 K-capture


where + means won to white, = means draw, - illegal by white's fault or black stalemated. (White stalemates are not separately identified, they count with the other draws.)
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic       TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions All times are GMT
Goto page 1, 2, 3, 4, 5  Next
Threaded
Page 1 of 5

 
Jump to:  
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