From: H.G. Muller Date: Mon, 15 Aug 2011 16:44:37 +0000 (+0200) Subject: profile X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=c75d2d23ecb6a2123ccf681852e9bef8c381ce22;p=xboard.git profile --- diff --git a/backend.c b/backend.c index e235dc1..286ec32 100644 --- a/backend.c +++ b/backend.c @@ -11318,13 +11318,13 @@ int GameContainsPosition(FILE *f, ListGame *lg) 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) { @@ -11384,10 +11384,9 @@ int GameContainsPosition(FILE *f, ListGame *lg) 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; } } diff --git a/gamelist.c b/gamelist.c index 712d9b9..11b06ac 100644 --- a/gamelist.c +++ b/gamelist.c @@ -224,13 +224,13 @@ struct { 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: @@ -330,9 +330,8 @@ struct { 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 diff --git a/moves.c b/moves.c index 194047d..a8f55b6 100644 --- a/moves.c +++ b/moves.c @@ -84,6 +84,7 @@ int BlackPiece(piece) return (int) piece >= (int) BlackPawn && (int) piece < (int) EmptySquare; } +#if 0 int SameColor(piece1, piece2) ChessSquare piece1, piece2; { @@ -96,6 +97,9 @@ int SameColor(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', @@ -184,13 +188,11 @@ void GenPseudoLegal(board, flags, callback, closure, filter) 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 ); @@ -1109,6 +1111,7 @@ ChessMove LegalityTest(board, flags, rf, ff, rt, ft, promoChar) { 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; @@ -1335,6 +1338,7 @@ void Disambiguate(board, flags, closure) { 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; diff --git a/parser.c b/parser.c index 09bb390..38ae6b7 100644 --- a/parser.c +++ b/parser.c @@ -144,7 +144,7 @@ int NextUnit(char **p) { // 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; }