if(lg->gameInfo.fen) ParseFEN(boards[scratch], &btm, lg->gameInfo.fen);
else CopyBoard(boards[scratch], initialPosition); // default start position
if(lg->moves && !QuickScan( boards[scratch], &moveDatabase[lg->moves] )) return -1; // quick scan rules out it is there
- if(btm) CopyBoard(boards[scratch+1], boards[scratch]), plyNr++;
- if(PositionMatches(boards[scratch + plyNr], boards[currentMove])) return plyNr;
+ if(btm) plyNr++;
+ if(PositionMatches(boards[scratch], boards[currentMove])) return plyNr;
fseek(f, lg->offset, 0);
yynewfile(f);
while(1) {
- yyboardindex = scratch + (plyNr&1);
- quickFlag = 1;
+ yyboardindex = scratch;
+ quickFlag = plyNr+1;
next = Myylex();
quickFlag = 0;
switch(next) {
break;
}
// Move encountered; peform it. We need to shuttle between two boards, as even/odd index determines side to move
- CopyBoard(boards[scratch + (plyNr+1&1)], boards[scratch + (plyNr&1)]);
plyNr++;
- ApplyMove(fromX, fromY, toX, toY, promoChar, boards[scratch + (plyNr&1)]);
- if(PositionMatches(boards[scratch + (plyNr&1)], boards[currentMove])) return plyNr;
+ ApplyMove(fromX, fromY, toX, toY, promoChar, boards[scratch]);
+ if(PositionMatches(boards[scratch], boards[currentMove])) return plyNr;
}
}
GameListFree(&gameList);
yynewfile(f);
gameNumber = 0;
- quickFlag = 1;
lastStart = (ChessMove) 0;
yyskipmoves = FALSE;
do {
- yyboardindex = scratch + (plyNr & 1);
+ yyboardindex = scratch;
offset = yyoffset();
+ quickFlag = plyNr + 1;
cm = (ChessMove) Myylex();
switch (cm) {
case GNUChessGame:
fromY = currentMoveString[1] - ONE;
toX = currentMoveString[2] - AAA;
toY = currentMoveString[3] - ONE;
- CopyBoard(boards[scratch + (plyNr+1&1)], boards[scratch + (plyNr&1)]);
plyNr++;
- ApplyMove(fromX, fromY, toX, toY, currentMoveString[4], boards[scratch + (plyNr&1)]);
+ ApplyMove(fromX, fromY, toX, toY, currentMoveString[4], boards[scratch]);
PackMove(fromX, fromY, toX, toY, currentMoveString[4]);
break;
case WhiteWins: // [HGM] rescom: save last comment as result details
return (int) piece >= (int) BlackPawn && (int) piece < (int) EmptySquare;
}
+#if 0
int SameColor(piece1, piece2)
ChessSquare piece1, piece2;
{
(int) piece2 >= (int) BlackPawn &&
(int) piece2 < (int) EmptySquare);
}
+#else
+#define SameColor(piece1, piece2) (piece1 < EmptySquare && piece2 < EmptySquare && (piece1 < BlackPawn) == (piece2 < BlackPawn))
+#endif
char pieceToChar[] = {
'P', 'N', 'B', 'R', 'Q', 'F', 'E', 'A', 'C', 'W', 'M',
for (rf = 0; rf < BOARD_HEIGHT; rf++)
for (ff = BOARD_LEFT; ff < BOARD_RGHT; ff++) {
ChessSquare piece;
- int rookRange = 1000;
+ int rookRange;
- if (flags & F_WHITE_ON_MOVE) {
- if (!WhitePiece(board[rf][ff])) continue;
- } else {
- if (!BlackPiece(board[rf][ff])) continue;
- }
+ if(board[rf][ff] == EmptySquare) continue;
+ if ((flags & F_WHITE_ON_MOVE) != (board[rf][ff] < BlackPawn)) continue; // [HGM] speed: wrong color
+ rookRange = 1000;
m = 0; piece = board[rf][ff];
if(PieceToChar(piece) == '~')
piece = (ChessSquare) ( DEMOTED piece );
{
LegalityTestClosure cl; ChessSquare piece, filterPiece, *castlingRights = board[CASTLING];
+ if(quickFlag) flags = flags & ~1 | quickFlag & 1; // [HGM] speed: in quick mode quickFlag specifies side-to-move.
if(rf == DROP_RANK) return LegalDrop(board, flags, ff, rt, ft);
piece = filterPiece = board[rf][ff];
if(PieceToChar(piece) == '~') filterPiece = DEMOTED piece;
{
int illegal = 0; char c = closure->promoCharIn;
+ if(quickFlag) flags = flags & ~1 | quickFlag & 1; // [HGM] speed: in quick mode quickFlag specifies side-to-move.
closure->count = closure->captures = 0;
closure->rf = closure->ff = closure->rt = closure->ft = 0;
closure->kind = ImpossibleMove;
{ // Main parser routine
int coord[4], n, result, piece, i;
char type[4], promoted, separator, slash, *oldp, *commentEnd, c;
- int wom = WhiteOnMove(yyboardindex);
+ int wom = quickFlag ? quickFlag&1 : WhiteOnMove(yyboardindex);
// ********* try white first, because it is so common **************************
if(**p == ' ' || **p == '\n' || **p == '\t') { parseStart = (*p)++; return Nothing; }