X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=backend.c;h=2c245d6d52b844f26cfd36c7575246bbda4990a8;hb=0332dbee9a4458560fe2c35aef0356cabca2bebc;hp=c364fe24484d37faade1a218bfd7168e2cd2851f;hpb=a0cb295983b04fd42e92f9e99da71917a1a2a97e;p=xboard.git diff --git a/backend.c b/backend.c index c364fe2..2c245d6 100644 --- a/backend.c +++ b/backend.c @@ -242,6 +242,7 @@ int endPV = -1; static int exiting = 0; /* [HGM] moved to top */ static int setboardSpoiledMachineBlack = 0 /*, errorExitFlag = 0*/; int startedFromPositionFile = FALSE; Board filePosition; /* [HGM] loadPos */ +int rightsBoard[BOARD_RANKS][BOARD_FILES]; /* [HGM] editrights */ 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 */ @@ -5791,6 +5792,7 @@ UserMoveTest(fromX, fromY, toX, toY, promoChar, captureOwn) click-click move is possible */ if (toX == -2 || toY == -2) { boards[0][fromY][fromX] = EmptySquare; + rightsBoard[fromY][fromX] = 0; return AmbiguousMove; } else if (toX >= 0 && toY >= 0) { boards[0][toY][toX] = boards[0][fromY][fromX]; @@ -5807,6 +5809,7 @@ UserMoveTest(fromX, fromY, toX, toY, promoChar, captureOwn) } } else boards[0][fromY][fromX] = EmptySquare; + rightsBoard[fromY][fromX] = rightsBoard[toY][toX] = 0; return AmbiguousMove; } return ImpossibleMove; @@ -6096,19 +6099,6 @@ UserMoveEvent(fromX, fromY, toX, toY, promoChar) FinishMove(moveType, fromX, fromY, toX, toY, promoChar); } -#if 0 -void -PromoDialog(int h, int w, Board board, Boolean clearBoard, char *title, int x, int y) -{ // dummy routine to mimic with pseudo-popup what front-end should do: - // display a popup with h x w mini-board, and divert any mouse clicks - // on it to the back-end routines RightClick and LeftClick, just - // like the mouse event hadler of the board widget does now. - // (Note it would have to off-set x if holdings are displayed!) - DisplayMessage("Click on your piece of choice", ""); - DrawPosition(TRUE, board); -} -#endif - int hTab[(int)EmptySquare/2+1] = { 1,1,1,1,1,1,2,1,2,3,2,3,3,3,2,3,4,3,3,4,4,3,4 }; int wTab[(int)EmptySquare/2+1] = { 1,1,2,3,4,5,3,7,4,3,5,4,4,5,7,5,4,6,6,5,5,7,6 }; Board promoBoard; @@ -6450,9 +6440,7 @@ int RightClick(ClickType action, int x, int y, int *xx, int *yy) xSqr = BOARD_WIDTH - 1 - xSqr; else ySqr = BOARD_HEIGHT - 1 - ySqr; - if(promotionChoice == 3 && action == Release - && promoBoard[ySqr][xSqr] != EmptySquare && (xSqr != fromX || ySqr != fromY) // not needed if separate window - ) { + if(promotionChoice == 3 && action == Release) { EditPositionMenuEvent(promoBoard[ySqr][xSqr], fromX, fromY); fromX = fromY = -1; promotionChoice = 0; @@ -11975,7 +11963,6 @@ EditGameEvent() SetGameInfo(); } - void EditPositionEvent() { @@ -11992,7 +11979,14 @@ EditPositionEvent() SetGameInfo(); if (currentMove > 0) CopyBoard(boards[0], boards[currentMove]); - + { int i, r, f; // [HGM] editrights: take note of existing rights + for(r=0; r=0; f--) + if(rightsBoard[0][f] == 2) { if(kf != NoRights) err=10; boards[0][CASTLING][2] = kf = f; } + for(f=BOARD_RGHT-1; f>=0; f--) + if(rightsBoard[0][f] == 1) { err++; boards[0][CASTLING][f=0; f--) + if(rightsBoard[BOARD_HEIGHT-1][f] == 2) { if(kf != NoRights) err=10; boards[0][CASTLING][5] = kf = f; } + for(f=BOARD_RGHT-1; f>=0; f--) + if(rightsBoard[BOARD_HEIGHT-1][f] == 1) { err++; boards[0][CASTLING][3+(f nrCastlingRights) DisplayError("unclear castling rights", 0); + boards[0][EP_STATUS] = EP_NONE; +#if 0 boards[0][CASTLING][2] = boards[0][CASTLING][5] = BOARD_WIDTH>>1; if(boards[0][0][BOARD_WIDTH>>1] == king) { boards[0][CASTLING][1] = boards[0][0][BOARD_LEFT] == WhiteRook ? 0 : NoRights; @@ -12034,6 +12043,7 @@ EditPositionDone(Boolean fakeRights) boards[0][CASTLING][4] = boards[0][BOARD_HEIGHT-1][BOARD_LEFT] == BlackRook ? 0 : NoRights; boards[0][CASTLING][3] = boards[0][BOARD_HEIGHT-1][BOARD_RGHT-1] == BlackRook ? BOARD_RGHT-1 : NoRights; } else boards[0][CASTLING][5] = NoRights; +#endif } SendToProgram("force\n", &first); if (blackPlaysFirst) { @@ -12131,6 +12141,7 @@ EditPositionMenuEvent(selection, x, y) { char buf[MSG_SIZ]; ChessSquare piece = boards[0][y][x]; + int rights = 0; // [HGM] editrights: most new pieces get no castling rights if (gameMode != EditPosition && gameMode != IcsExamining) return; @@ -12154,6 +12165,7 @@ EditPositionMenuEvent(selection, x, y) } } else { boards[0][y][x] = p; + rightsBoard[y][x] = 0; // [HGM] editrights: clear all castling rights } } } @@ -12171,6 +12183,18 @@ EditPositionMenuEvent(selection, x, y) SetBlackToPlayEvent(); break; + case NoRights: + rightsBoard[y][x] = 0; + break; + + case GrantRights: + { ChessSquare p = boards[0][y][x]; + rightsBoard[y][x] = 1; + if(p == WhiteKing || p == WhiteUnicorn || p == BlackKing || p == BlackUnicorn) + rightsBoard[y][x] = 2; + } + break; + case EmptySquare: if (gameMode == IcsExamining) { if (x < BOARD_LEFT || x >= BOARD_RGHT) break; // [HGM] holdings @@ -12217,12 +12241,24 @@ EditPositionMenuEvent(selection, x, y) selection = (ChessSquare)((int)selection - (int)WhiteQueen + (int)WhiteFerz); goto defaultlabel; + case WhiteRook: // [HGM] editrights: corner Rooks get castling rights by default + if(y == 0 && (x == BOARD_LEFT || x == BOARD_RGHT-1)) rights = 1; + goto defaultlabel; + + case BlackRook: + if(y == BOARD_HEIGHT-1 && (x == BOARD_LEFT || x == BOARD_RGHT-1)) rights = 1; + goto defaultlabel; + case WhiteKing: case BlackKing: if(gameInfo.variant == VariantXiangqi) selection = (ChessSquare)((int)selection - (int)WhiteKing + (int)WhiteWazir); if(gameInfo.variant == VariantKnightmate) selection = (ChessSquare)((int)selection - (int)WhiteKing + (int)WhiteUnicorn); + case WhiteUnicorn: + case BlackUnicorn: + if(y == (selection <= WhiteKing ? 0 : BOARD_HEIGHT-1) && (x == BOARD_WIDTH>>1)) + rights = 2; // [HGM] editrights: King on right-center file gets rights default: defaultlabel: if (gameMode == IcsExamining) { @@ -12247,6 +12283,7 @@ EditPositionMenuEvent(selection, x, y) } } else boards[0][y][x] = selection; + rightsBoard[y][x] = rights; // [HGM] editrights: set default rights of created piece DrawPosition(TRUE, boards[0]); } break;