ChessSquare p = boards[moveNr][r][f];
if(f == BOARD_LEFT-1 || f == BOARD_RGHT) continue; // between board and holdings
if(p != EmptySquare){
- int j = (int)p;
+ int j = (int)p, promoted = 0;
j -= (j >= (int)BlackPawn) ? (int)BlackPawn :(int)WhitePawn;
+ if(j >= CHUPROMOTED WhitePawn) promoted++, j -= CHUPROMOTED WhitePawn;
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);
Zobrist = (Zobrist << 48) ^ (Zobrist >> 16);
break;
}
+ if(promoted) Zobrist ^= 123456789*RandomPiece[squareNr & 63];
if(squareNr & 64) Zobrist = (Zobrist << 8) ^ (Zobrist >> 56);
if(squareNr & 128) Zobrist = (Zobrist << 4) ^ (Zobrist >> 60);
// holdings have separate (additive) key, to encode presence of multiple pieces on same square
tr = t / width;
tf = t % width;
move_s[0] = ff + 'a';
- move_s[1] = fr + '1' - (BOARD_HEIGHT > 9);
+ move_s[1] = fr + '1' - (BOARD_HEIGHT == 10);
move_s[2] = tf + 'a';
- move_s[3] = tr + '1' - (BOARD_HEIGHT > 9);
+ move_s[3] = 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
+ else if(p != 7) p = 8; // use '+' for all others that do not explicitly defer
+ }
// kludge: encode drops as special promotion code
if(gameInfo.holdingsSize && p == 9) {
move_s[0] = f + '@'; // from square encodes piece type
move_s[1] = '@'; // drop symbol
p = 0;
+ } else if(p == 10) { // decode Lion move
+
+ p = 0;
}
// add promotion piece, if any
return count;
}
+static int dirty;
+
int
ReadFromBookFile (int moveNr, char *book, entry_t entries[])
{ // retrieve all entries for given position from book in 'entries', return number.
static char curBook[MSG_SIZ];
if(book == NULL) return -1;
+ if(dirty) { if(f) fclose(f); dirty = 0; f = NULL; }
if(!f || strcmp(book, curBook)){ // keep book file open until book changed
strncpy(curBook, book, MSG_SIZ);
if(f) fclose(f);
MovesToText(int count, entry_t *entries)
{
int i, totalWeight = 0;
- char algMove[6];
+ char algMove[12];
char *p = (char*) malloc(40*count+1);
for(i=0; i<count; i++) totalWeight += entries[i].weight;
*p = 0;
int from = fromX - BOARD_LEFT + fromY * width;
for(i=0; promote_pieces[i]; i++) if(promote_pieces[i] == promoChar) break;
if(!promote_pieces[i]) i = 0;
+ else if(i == 9 && gameInfo.variant == VariantChu) i = 1; // on 12x12 only 3 promotion codes available, so use 1 to indicate promotion
if(fromY == DROP_RANK) i = 9, from = ToUpper(PieceToChar(fromX)) - '@';
return to + (i * width * BOARD_HEIGHT + from) * width * BOARD_HEIGHT;
}
writepos += len2;
} while(len1);
}
+ dirty = 1;
fclose(f);
}
}
if(appData.debugMode) fprintf(debugFP, "add game to book (%d-%d)\n", backwardMostMove, forwardMostMove);
-
for(i=backwardMostMove; i<forwardMostMove && i < 2*appData.bookDepth; i++)
AddToBook(i, WhiteOnMove(i) ? result : 2-result); // flip result when black moves
}