X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=backend.c;h=1e1f78a6a49393886f1ec6a7d547d5b050878bcf;hb=6112f15dc9df5810f2e487f32302c251069c2333;hp=18d48ce94ce32ec714fcd010df32c46cd47bea63;hpb=d6a5884d9a6af414ed26d5b70a1b3dcf131b1e9c;p=xboard.git diff --git a/backend.c b/backend.c index 18d48ce..1e1f78a 100644 --- a/backend.c +++ b/backend.c @@ -243,7 +243,11 @@ static int exiting = 0; /* [HGM] moved to top */ static int setboardSpoiledMachineBlack = 0 /*, errorExitFlag = 0*/; int startedFromPositionFile = FALSE; Board filePosition; /* [HGM] loadPos */ Board partnerBoard; /* [HGM] bughouse: for peeking at partner game */ +Boolean partnerBoardValid = 0; +char partnerStatus[MSG_SIZ]; Boolean partnerUp; +Boolean originalFlip; +Boolean twoBoards = 0; char endingGame = 0; /* [HGM] crash: flag to prevent recursion of GameEnds() */ int whiteNPS, blackNPS; /* [HGM] nps: for easily making clocks aware of NPS */ VariantClass currentlyInitializedVariant; /* [HGM] variantswitch */ @@ -3461,6 +3465,7 @@ read_from_ics(isr, closure, data, count, error) ZippyGameStart(whitename, blackname); } #endif /*ZIPPY*/ + partnerBoardValid = FALSE; // [HGM] bughouse continue; } @@ -3501,6 +3506,7 @@ read_from_ics(isr, closure, data, count, error) Reset(TRUE, TRUE); } #endif /*ZIPPY*/ + if(appData.bgObserve && partnerBoardValid) DrawPosition(TRUE, partnerBoard); continue; } @@ -3647,7 +3653,7 @@ read_from_ics(isr, closure, data, count, error) gameInfo.white, white_holding, gameInfo.black, black_holding); } - + if(!partnerUp) // [HGM] bughouse: when peeking at partner game we already know what he captured... DrawPosition(FALSE, boards[currentMove]); DisplayTitle(str); } else if(appData.bgObserve) { // [HGM] bughouse: holdings of other game => background @@ -3659,7 +3665,9 @@ read_from_ics(isr, closure, data, count, error) /* [HGM] copy holdings to partner-board holdings area */ CopyHoldings(partnerBoard, white_holding, WhitePawn); CopyHoldings(partnerBoard, black_holding, BlackPawn); + if(twoBoards) { partnerUp = 1; flipView = !flipView; } // [HGM] dual: always draw if(partnerUp) DrawPosition(FALSE, partnerBoard); + if(twoBoards) { partnerUp = 0; flipView = !flipView; } } } /* Suppress following prompt */ @@ -3736,7 +3744,7 @@ ParseBoard12(string) char promoChar; int ranks=1, files=0; /* [HGM] ICS80: allow variable board size */ char *bookHit = NULL; // [HGM] book - Boolean weird = FALSE, reqFlag = FALSE; + Boolean weird = FALSE, reqFlag = FALSE, repaint = FALSE; fromX = fromY = toX = toY = -1; @@ -3813,7 +3821,6 @@ ParseBoard12(string) if((gameMode == IcsPlayingWhite || gameMode == IcsPlayingBlack) && newGameMode == IcsObserving && appData.bgObserve) { // [HGM] bughouse: don't act on alien boards while we play. Just parse the board and save it */ - char buf[MSG_SIZ]; for (k = 0; k < ranks; k++) { for (j = 0; j < files; j++) board[k][j+gameInfo.holdingsWidth] = CharToPiece(board_chars[(ranks-1-k)*(files+1) + j]); @@ -3823,10 +3830,14 @@ ParseBoard12(string) } } CopyBoard(partnerBoard, board); - if(partnerUp) DrawPosition(FALSE, partnerBoard); - sprintf(buf, "W: %d:%d B: %d:%d (%d-%d) %c", white_time/60000, (white_time%60000)/1000, + if(appData.dualBoard && !twoBoards) { twoBoards = repaint = 1; InitDrawingSizes(-2,0); } + if(twoBoards) { partnerUp = 1; flipView = !flipView; } // [HGM] dual + if(partnerUp) DrawPosition(repaint, partnerBoard); + if(twoBoards) { partnerUp = 0; flipView = !flipView; } // [HGM] dual + sprintf(partnerStatus, "W: %d:%02d B: %d:%02d (%d-%d) %c", white_time/60000, (white_time%60000)/1000, (black_time/60000), (black_time%60000)/1000, white_stren, black_stren, to_play); - DisplayMessage(buf, ""); + DisplayMessage(partnerStatus, ""); + partnerBoardValid = TRUE; return; } @@ -4359,6 +4370,7 @@ ParseBoard12(string) ClearPremoveHighlights(); j = seekGraphUp; seekGraphUp = FALSE; // [HGM] seekgraph: when we draw a board, it overwrites the seek graph + if(partnerUp) { flipView = originalFlip; partnerUp = FALSE; j = TRUE; } // [HGM] bughouse: restore view DrawPosition(j, boards[currentMove]); DisplayMove(moveNum - 1); @@ -4888,14 +4900,17 @@ Boolean LoadMultiPV(int x, int y, char *buf, int index, int *start, int *end) { int startPV; + char *p; if(index < 0 || index >= strlen(buf)) return FALSE; // sanity lastX = x; lastY = y; while(index > 0 && buf[index-1] != '\n') index--; // beginning of line startPV = index; - while(buf[index] != '\n') if(buf[index++] == '\t') startPV = index; - index = startPV; - while(buf[index] && buf[index] != '\n') index++; + while(buf[index] != '\n') if(buf[index++] == '\t') startPV = index; + if(index == startPV && (p = StrCaseStr(buf+index, "PV="))) startPV = p - buf + 3; + index = startPV; + do{ while(buf[index] && buf[index] != '\n') index++; + } while(buf[index] == '\n' && buf[index+1] == '\\' && buf[index+2] == ' ' && index++); // join kibitzed PV continuation line buf[index] = 0; ParsePV(buf+startPV, FALSE); *start = startPV; *end = index-1; @@ -6433,8 +6448,19 @@ int RightClick(ClickType action, int x, int y, int *fromX, int *fromY) if((gameMode == IcsPlayingWhite || gameMode == IcsPlayingBlack) && !appData.zippyPlay && appData.bgObserve) { // [HGM] bughouse: show background game - if(action == Press) { flipView = !flipView; DrawPosition(TRUE, partnerBoard); partnerUp = TRUE; } else - if(action == Release) { flipView = !flipView; DrawPosition(TRUE, boards[currentMove]); partnerUp = FALSE; } + if(!partnerBoardValid) return -2; // suppress display of uninitialized boards + if( appData.dualBoard) return -2; // [HGM] dual: is already displayed + if(action == Press) { + originalFlip = flipView; + flipView = !flipView; // temporarily flip board to see game from partners perspective + DrawPosition(TRUE, partnerBoard); + DisplayMessage(partnerStatus, ""); + partnerUp = TRUE; + } else if(action == Release) { + flipView = originalFlip; + DrawPosition(TRUE, boards[currentMove]); + partnerUp = FALSE; + } return -2; } @@ -8879,7 +8905,10 @@ GameEnds(result, resultDetails, whosays) if(endingGame) return; /* [HGM] crash: forbid recursion */ endingGame = 1; - + if(twoBoards) { // [HGM] dual: switch back to one board + twoBoards = partnerUp = 0; InitDrawingSizes(-2, 0); + DrawPosition(TRUE, partnerBoard); // observed game becomes foreground + } if (appData.debugMode) { fprintf(debugFP, "GameEnds(%d, %s, %d)\n", result, resultDetails ? resultDetails : "(null)", whosays); @@ -10149,7 +10178,9 @@ LoadGame(f, gameNumber, title, useList) if (numPGNTags > 0){ char *tags; if (gameInfo.variant == VariantNormal) { - gameInfo.variant = StringToVariant(gameInfo.event); + VariantClass v = StringToVariant(gameInfo.event); + // [HGM] do not recognize variants from event tag that were introduced after supporting variant tag + if(v < VariantShogi) gameInfo.variant = v; } if (!matchMode) { if( appData.autoDisplayTags ) { @@ -13336,8 +13367,10 @@ ReceiveFromProgram(isr, closure, message, count, error) sscanf(message, "error %c", &c)!=1 && sscanf(message, "illegal %c", &c)!=1 && sscanf(message, "tell%c", &c)!=1 && sscanf(message, "0-1 %c", &c)!=1 && sscanf(message, "1-0 %c", &c)!=1 && sscanf(message, "1/2-1/2 %c", &c)!=1 && - sscanf(message, "pong %c", &c)!=1 && start != '#') - { quote = "# "; print = (appData.engineComments == 2); } + sscanf(message, "pong %c", &c)!=1 && start != '#') { + quote = appData.engineComments == 2 ? "# " : "### NON-COMPLIANT! ### "; + print = (appData.engineComments >= 2); + } message[0] = start; // restore original message } if(print) {