Hello,
how did the SF team accomplish the problem with "en passant" capture of a pawn?
see https://en.wikipedia.org/wiki/En_passant
cf. https://www.fide.com/FIDE/handbook/LawsOfChess.pdf
3.7
a. The pawn may move forward to the unoccupied square immediately in front of it on the same file, or
b. on its first move the pawn may move as in 3.7.a or alternatively it may advance two squares along the same file provided both squares are unoccupied, or
c. the pawn may move to a square occupied by an opponent’s piece, which is diagonally in front of it on an adjacent file, capturing that piece.
d. A pawn attacking a square crossed by an opponent’s pawn which has advanced two squares in one move from its original square may capture this opponent’s pawn as though the latter had been moved only one square. This capture is only legal on the move following this advance and is called an ‘en passant’ capture.
I ask you because StuckFish https://github.com/MaxCarlson/StuckFish has obviously no knowledge about "en passant" (in passing)
FIDE rule.
[White "ChessBrainVB"]
[Black "StuckFish"]
[Result "1-0"]
[TimeControl "40/240:40/240:40/240"]
[Opening "French"]
[ECO "C10"]
[Variation "3.Nc3 Nc6"]
[Termination "rules infraction"]
[PlyCount "23"]
[WhiteType "program"]
[BlackType "program"]
1.e4 e6 2. d4 d5 3. Nc3 Nc6 4. Nf3 Bb4 5. e5 Nge7 6. Bd3 b6 7. O-O Bxc3 8. bxc3 h6 9.Nh4 Bb7 10. Qg4 g5 11. Nf3 f5 12. exf6 1-0
A sceenshot of the concerning "en passant" section (>source code) would probably be useful in this case.
Best wishes,
Norbert
Stockfish Chess 8 - en passant rule
Moderators: hgm, Rebel, chrisw
-
- Posts: 1643
- Joined: Tue May 20, 2008 4:57 pm
- Location: Augsburg - Germany
-
- Posts: 17
- Joined: Fri Sep 15, 2017 11:52 pm
Re: Stockfish Chess 8 - en passant rule
Here is Stockfish's implementation:
https://github.com/official-stockfish/S ... sition.cpp
Namely
and
EDIT: Similar code can be found in Stuckfish:
https://github.com/MaxCarlson/StuckFish ... boards.cpp
https://github.com/official-stockfish/S ... sition.cpp
Namely
Code: Select all
// Set en-passant square if the moved pawn can be captured
if ( (int(to) ^ int(from)) == 16
&& (attacks_from<PAWN>(to - pawn_push(us), us) & pieces(them, PAWN)))
{
st->epSquare = (from + to) / 2;
k ^= Zobrist::enpassant[file_of(st->epSquare)];
}
Code: Select all
if (type_of(m) == ENPASSANT)
{
capsq -= pawn_push(us);
assert(pc == make_piece(us, PAWN));
assert(to == st->epSquare);
assert(relative_rank(us, to) == RANK_6);
assert(piece_on(to) == NO_PIECE);
assert(piece_on(capsq) == make_piece(them, PAWN));
board[capsq] = NO_PIECE; // Not done by remove_piece()
}
https://github.com/MaxCarlson/StuckFish ... boards.cpp
-
- Posts: 216
- Joined: Sun Jan 22, 2017 8:30 pm
- Location: Russia
Re: Stockfish Chess 8 - en passant rule
I'm not a specialist in Stuckfish's source code, but a quick look at it reveals that its zobristh.cpp (the Zobrist hash implementation that's apparently different from Stockfish's) contains the following comment (line 146):
//EnPassant and castling stuff add later
Besides, the author (MaxCarlson) states in the titles of the latest commits to a lot of files, 'Not working commit. Added EP stuff, still non functional though.'
So it appears that, in its current state, Stuckfish doesn't save the info about the possibility of an e.p. move correctly into the TT.
In the game in question, it might have encountered the position arising after Black's move 11 in some earlier search and saved it into the TT without extending the search (perhaps the possibility of e.p. doesn't automatically trigger q-search in Stuckfish, which is a bug), 'forgetting' that e.p. is possible there, and then, after this position appeared on the board, Stuckfish retrieved it from the TT, mistakenly thinking that e.p. is impossible.
You've been unlucky to test Stuckfish at the moment when its e.p. handling is yet broken as of the last commit that happened 10 hours ago. Wait until the author fixes the 'e.p. stuff'.
//EnPassant and castling stuff add later
Besides, the author (MaxCarlson) states in the titles of the latest commits to a lot of files, 'Not working commit. Added EP stuff, still non functional though.'
So it appears that, in its current state, Stuckfish doesn't save the info about the possibility of an e.p. move correctly into the TT.
In the game in question, it might have encountered the position arising after Black's move 11 in some earlier search and saved it into the TT without extending the search (perhaps the possibility of e.p. doesn't automatically trigger q-search in Stuckfish, which is a bug), 'forgetting' that e.p. is possible there, and then, after this position appeared on the board, Stuckfish retrieved it from the TT, mistakenly thinking that e.p. is impossible.
You've been unlucky to test Stuckfish at the moment when its e.p. handling is yet broken as of the last commit that happened 10 hours ago. Wait until the author fixes the 'e.p. stuff'.
-
- Posts: 216
- Joined: Sun Jan 22, 2017 8:30 pm
- Location: Russia
Re: Stockfish Chess 8 - en passant rule
There is code for e.p. move making, though (see the below code snippet from bitboards.cpp, lines 311-331), and the e.p. square is saved in the game state variable 'st', but for some reason, the code isn't working correctly yet. The zobrist.zEnPassant function is definitely not working yet.
Anyway, my point is that the malfunctioning has been caused by the refactoring that MaxCarlson has been doing, but the original Stockfish code of course handles e.p. correctly.
Code: Select all
if (m.piece == PAWN) {
//if the pawn move is two forward,
//and there is an enemy pawn positioned to en passant
if ((m.to ^ m.from) == 16
&& (psuedoAttacks(PAWN, color, m.from + pawn_push(color)) & pieces(them, PAWN))) {
st->epSquare = (m.from + m.to) / 2;
zobrist.zobristKey ^= zobrist.zEnPassant[file_of(st->epSquare)];
}
//en passant
else if (m.flag == 'E') {
int ePawnSq = ep_square() + pawn_push(them);
//remove the pawn captured by ep
removePiece(PAWN, them, ePawnSq);
zobrist.zobristKey ^= zobrist.zArray[them][PAWN][ePawnSq];
bInfo.PawnKey ^= zobrist.zArray[them][PAWN][ePawnSq];
bInfo.sideMaterial[them] -= SORT_VALUE[PAWN];
}