X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=backend.c;h=3fa521b6988ac25ac20eae0bc37ae9d0a69dd69c;hb=8a25cc70afe43a774d68bd1e78a5ce63a1031ceb;hp=34b4c36dda644fda8bf6c5c61f22fd9c688bc89c;hpb=3aadc726d957f0e8cdeae3c65ff19808a979a4e3;p=xboard.git diff --git a/backend.c b/backend.c index 34b4c36..3fa521b 100644 --- a/backend.c +++ b/backend.c @@ -5,7 +5,7 @@ * Massachusetts. * * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006, - * 2007, 2008, 2009 Free Software Foundation, Inc. + * 2007, 2008, 2009, 2010 Free Software Foundation, Inc. * * Enhancements Copyright 2005 Alessandro Scotti * @@ -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,49 +6099,66 @@ UserMoveEvent(fromX, fromY, toX, toY, promoChar) FinishMove(moveType, fromX, fromY, toX, toY, promoChar); } -void -PromoDialog(int h, int w, Board board, Boolean clearBoard) -{ // dummy routine to mimic with pseudo-popup what front-end should do: - // display a popup with h x w mini-board - int i, j; - DisplayMessage("Click on your piece of choice", ""); - DrawPosition(TRUE, board); -} - 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; int promotionChoice = 0; -void PromoPopUp(ChessSquare piece) +void +PiecePopUp(int x, int y) +{ + int i, j, h, w, nWhite=0, nBlack=0; + ChessSquare list[EmptySquare]; + for(i=0; iBOARD_RGHT-BOARD_LEFT) { w = BOARD_RGHT - BOARD_LEFT; h = (j+w-1)/w; } + for(i=0; i 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; } + if(kf == NoRights) kf = 4; + 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; } + if(kf == NoRights) kf = 4; + 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; @@ -11985,6 +12045,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) { @@ -12082,6 +12143,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; @@ -12105,6 +12167,7 @@ EditPositionMenuEvent(selection, x, y) } } else { boards[0][y][x] = p; + rightsBoard[y][x] = 0; // [HGM] editrights: clear all castling rights } } } @@ -12122,6 +12185,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 @@ -12168,12 +12243,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) { @@ -12198,6 +12285,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;