3

For artistic purposes, I would like to create and study engine games in which only one side is able to castle.

For this, I need to compile a version of Stockfish which never castles, and doesn't consider its own castling in its calculations, whereas calculates with castling for the opponent.

I have gone through the types.h file and found the following:

enum MoveType {
  NORMAL,
  PROMOTION = 1 << 14,
  ENPASSANT = 2 << 14,
  CASTLING  = 3 << 14
};

enum CastlingRights {
  NO_CASTLING,
  WHITE_OO,
  WHITE_OOO = WHITE_OO << 1,
  BLACK_OO  = WHITE_OO << 2,
  BLACK_OOO = WHITE_OO << 3,

  KING_SIDE      = WHITE_OO  | BLACK_OO,
  QUEEN_SIDE     = WHITE_OOO | BLACK_OOO,
  WHITE_CASTLING = WHITE_OO  | WHITE_OOO,
  BLACK_CASTLING = BLACK_OO  | BLACK_OOO,
  ANY_CASTLING   = WHITE_CASTLING | BLACK_CASTLING,

  CASTLING_RIGHT_NB = 16
};

What can I do to disable castling in moves and calculations of Stockfish?

  • 2
    replace two lines with BLACK_00 = 0, BLACK_000 = 0, might work. Depends on how all the other code is written. – Aganju Jul 4 at 1:21
  • 1
    @Aganju This works, thank you! Could you please post your comment as an answer so that I can accept it? – Ritesh Singh Jul 4 at 3:15
  • 1
    Can you use an opening book that allows one side to castle, but not the other? E.g. 1. Nf3 Nf6 2. Rg1 Ng8 3. Rh1 Nf6 4. Ng1 Ng8 disables White kingside castling, but not Black, and the game starts from the opening position. – Allure Jul 4 at 3:43
  • 2
    You could just set the initial position from a FEN in which the castling rights have been removed from one side (that is, the usual starting position FEN but with KQkq changed to KQ or kq). This will give the correct move numbering (whereas Allure’s suggestion would number the first real move as move 5). – Stephen Jul 4 at 6:53
  • 2
    @Stephen That should probably be an answer. – D M Jul 4 at 14:44
6

There is no need to compile your own version of Stockfish for this. Instead you can just start from a position that omits castling rights for one side or the other. The FEN for the initial position without castling rights for White is

rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w kq - 0 1

and the FEN for the initial position without castling rights for Black is

rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQ - 0 1

The FEN can be entered into Stockfish using the UCI command

position fen FEN

where FEN should be replaced by the FEN in question.

| improve this answer | |
  • Of course, this works for any UCI engine, not just Stockfish. – Stephen Aug 12 at 6:59
2

Without reviewing the complete code (which is probably humongous), it is difficult to give a proven right answer.

However, it should work if you replace the lines for the black castling possibilities by BLACK_00 = 0, BLACK_000 = 0, (or respectively for the white, if you want). This should lead to all tests in the code returning 'black castling not possible', which is the intention.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.