X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=book.c;h=cfc25c8d95a5a0a3f5745eebbb54b05aea6a03ba;hb=9089c023e881715fe42fe104d24df44489cd3e35;hp=520d941e9bfa8ae5b62ca105bcd69b1365dcc071;hpb=2a1e296dac2afd76b0661e82ca5da911eef20697;p=xboard.git diff --git a/book.c b/book.c index 520d941..cfc25c8 100644 --- a/book.c +++ b/book.c @@ -315,7 +315,7 @@ hash (int moveNr) if(p != EmptySquare){ int j = (int)p, promoted = 0; j -= (j >= (int)BlackPawn) ? (int)BlackPawn :(int)WhitePawn; - if(j >= CHUPROMOTED WhitePawn) promoted++, j -= CHUPROMOTED WhitePawn; + if(j >= WhitePBishop && j != WhiteKing) promoted++, j -= WhiteTokin; if(j > (int)WhiteQueen) j++; // make space for King if(j > (int) WhiteKing) j = (int)WhiteQueen + 1; p_enc = 2*j + ((int)p < (int)BlackPawn); @@ -484,8 +484,11 @@ find_key (FILE *f, uint64 key, entry_t *entry) } } +static int xStep[] = { 0, 1, 1, 1, 0,-1,-1,-1 }; +static int yStep[] = { 1, 1, 0,-1,-1,-1, 0, 1 }; + void -move_to_string (char move_s[6], uint16 move) +move_to_string (char move_s[20], uint16 move) { int f,fr,ff,t,tr,tf,p; int width = BOARD_RGHT - BOARD_LEFT, size; // allow for alternative board formats @@ -499,10 +502,7 @@ move_to_string (char move_s[6], uint16 move) t = move % size; tr = t / width; tf = t % width; - move_s[0] = ff + 'a'; - move_s[1] = fr + '1' - (BOARD_HEIGHT == 10); - move_s[2] = tf + 'a'; - move_s[3] = tr + '1' - (BOARD_HEIGHT == 10); + snprintf(move_s, 9, "%c%d%c%d", ff + 'a', fr + 1 - (BOARD_HEIGHT == 10), tf + 'a', tr + 1 - (BOARD_HEIGHT == 10)); if(IS_SHOGI(gameInfo.variant) && p) { if(p == 2) p = 10; // Lion moves, for boards so big that 10 is out of range @@ -515,16 +515,20 @@ move_to_string (char move_s[6], uint16 move) move_s[1] = '@'; // drop symbol p = 0; } else if(p == 10) { // decode Lion move - + int i = t & 7, j = t >> 3 & 7; + tf = ff + xStep[i] + xStep[j]; tr = fr + yStep[i] + yStep[j]; // calculate true to-square + snprintf(move_s, 20, "%c%d%c%d,%c%d%c%d", ff + 'a', fr + 1 - (BOARD_HEIGHT == 10), + ff + xStep[i] + 'a', fr + yStep[i] + 1 - (BOARD_HEIGHT == 10), + ff + xStep[i] + 'a', fr + yStep[i] + 1 - (BOARD_HEIGHT == 10), + tf + 'a', tr + 1 - (BOARD_HEIGHT == 10) ); p = 0; } // add promotion piece, if any if(p){ - move_s[4] = promote_pieces[p]; - move_s[5] = '\0'; - }else{ - move_s[4] = '\0'; + int len = strlen(move_s); + move_s[len] = promote_pieces[p]; + move_s[len+1] = '\0'; } if(gameInfo.variant != VariantNormal) return; @@ -734,8 +738,10 @@ MovesToText(int count, entry_t *entries) for(i=0; i= 0) { // multi-leg move + int dx = killX - fromX, dy = killY - fromY; + for(i=0; i<8; i++) if(dx == xStep[i] && dy == yStep[i]) { + int j; + dx = toX - killX; dy = toY - killY; + for(j=0; j<8; j++) if(dx == xStep[j] && dy == yStep[j]) { + // special encoding in to-square, with promoType = 2. Assumes board >= 64 squares! + return i + 8*j + (2 * width * BOARD_HEIGHT + from) * width * BOARD_HEIGHT; + } + } + i = 0; // if not a valid Lion move, ignore kill-square and promoChar + } return to + (i * width * BOARD_HEIGHT + from) * width * BOARD_HEIGHT; } @@ -776,6 +794,7 @@ TextToMoves (char *text, int moveNum, entry_t *entries) valid = ParseOneMove(text, moveNum, &moveType, &fromX, &fromY, &toX, &toY, &promoChar); text = strstr(text, yy_textstr) + strlen(yy_textstr); // skip what we parsed if(!valid || moveType != NormalMove && moveType != WhiteDrop && moveType != BlackDrop + && moveType != FirstLeg && moveType != WhitePromotion && moveType != BlackPromotion && moveType != WhiteCapturesEnPassant && moveType != BlackCapturesEnPassant && moveType != WhiteKingSideCastle && moveType != BlackKingSideCastle @@ -787,7 +806,7 @@ TextToMoves (char *text, int moveNum, entry_t *entries) entries[count].learnPoints = 0; entries[count].learnCount = 0; } - entries[count].move = CoordsToMove(fromX, fromY, toX, toY, promoChar); + entries[count].move = CoordsToMove(fromX, fromY, toX, toY, promoChar); killX = killY = -1; entries[count].key = hashKey; entries[count].weight = w; count++;