hgm wrote: ↑Sat Sep 22, 2018 5:10 pm
Note that micro-Max says enCap = toSqr += ray, which is not equivalent to
enCap = toSqr;
toSqr += ray;
but to
toSqr += ray;
enCap = toSqr;
En passant capture is only possible if the preceding move was a double-push. You have to tell that to the move generator by passing it the number of the e.p. square. If you do that it should print the e.p. move. If not, it assumes this is not a valid move, so it doesn't print it.
The place where you put the print statements would in principle print every move. The code you wrote does not generate castling moves, though. So they are not printed. Micro-Max generates castlings (and Pawn double-pushes) through the lines
Code: Select all
if(p<3&6*k+(y&V)==S /* pawn on 3rd/6th, or */
||(u&~24)==36&j==7&& /* virgin K moving sideways,*/
G&M&&b[G=(x|7)-(r>>1&7)]&32 /* 1st, virgin R in corner G*/
&&!(b[G^1]|b[G^2]) /* 2 empty sqrs. next to R */
){F=y;t--;} /* unfake capt., enable e.p.*/
just before the end of the range loop. To force termination of this loop after one iteration for leapers, micro-Max faked the move was a capture by incrementing t (= 'capt' in your terminology). If it was the first sideway step of a virgin King (and a host of other conditions are fulfilled) it eventually does t--; here to undo that, so that the range loop will not terminate if the move was not a real capture. Then the King (or Pawn) would make a second step. In addition 'e.p. rights' are created by setting F to the toSqr (which at this point is where the first step ended.
The other conditions are:
Code: Select all
(coloredPiece & ~24) == 36 This tests whether the piece is a virgin King; & ~24 obliterates the color, 36 = 4 (King code) + 32 (virgin)
j == 7 Tests for sideway move (Note moves to left and right use same index j in step table)
G&M This is rookFromSqr & 0x88, and tests if rookToSqr is still invalid (i.e. whether this is not the 3rd step)
rookFromSqr = (fromSqr | 7) - (ray >> 1 & 7) Calculates where the Rook is; note that ray>>1 is 0 or -1, after &7 this becomes 0 or 7
board[rookFromSqr]&32 Tests if the corner piece is virgin (in which case it must be a Rook)
board[rookFromSqr^1] piece next to the Rook
board[rookFromSqr^2] piece two steps away from the Rook
It is fine to ask questions in public; I actually prefer that. You never know who else the answer might be useful to, now or later.
I've fixed my code and now enPassant captures are printed. It's also almost clear with castling code, i say "almost" because on the one hand I understand why it doesn't print castling moves correctly, but unfortunately have no idea how to fix it. After for about 3 hours of researching micro-Max code I've noticed one tiny little detail causing the disaster - in move generation tutorial appears this code:
Code: Select all
static int o[] = {
-16,-15,17,0, /* downstream pawn */
16,15,17,0, /* upstream pawn */
1,-1,16,-16,0, /* rook */
1,-1,16,-16,15,-15,17,-17,0, /* king, queen and bishop */
14,-14,18,-18,31,-31,33,-33,0, /* knight */
-1,3,21,12,16,7,12 /* directory */
};
please notice the directions are given as + and -
but in source code:
Code: Select all
o[]={-16,-15,-17,0,1,16,0,1,16,15,17,0,14,18,31,33,0, /* step-vector lists */
7,-1,11,6,8,3,6, ....
the directory line changes from -1,3,21,12,16,7,12 to 7,-1,11,6,8,3,6, I assume this is the whole point,
I mean the condition (piece & ~24) == 36 & dir == 7 (dir is your var j) is never to happen. I might me wrong but feel that here is the problem. I don't want to obfuscate the code via using only one sided directions, but in this case the expression
(piece & ~24) == 36 & dir == 7 probably has to be rewritten... somehow, please help.
I tried blindly doing like so (piece & ~24) == 36 & dir == 14 - this caused castling only one side
Also another questions are arising:
1. I've written ParseFen(*fen) function to setup position via parsing FEN string. Setting up pieces and en passant square to pass it as argument to search() are just fine, but how can I pass castling rights??? May be via playing with virgin bits on rooks and queens?
2. Another issue is I doubt whether UCI protocol I got used to is applicable with such a all-in-one inlined design? May be switching to xboard/winboard is reasonable and solves that problem?