lantonov / asmFish

A continuation of the nice project asmFish by Mohammed Li. Latest version: 07.08.2019
https://lantonov.github.io/asmFish/
Other
118 stars 49 forks source link

Help request #29

Closed lantonov closed 7 years ago

lantonov commented 7 years ago

Need help with the patch "Keep pawns on both flanks" by snicolet

tthsqe12 commented 7 years ago

You should be able to give this a try if you know what all of the instructions around https://github.com/lantonov/asmFish/blob/master/asmFish/guts/Evaluate.asm#L1608 do. You will also want to define the symbols QueenSide and KingSide. If you are not able to to do this or it is too much trouble, I (or someone else) will have a version soon.

lantonov commented 7 years ago

I would really try if I know the instructions but I don't, unfortunately. Reading, for example, for popcnt "return the count of number of bits set to 1" I don't understand what is the use of that count, etc. Removing code is easy for me. Problems start when I have to add code.

My ponderings (please don't laugh):

     popcnt   r9, qword[rbp+Pos.typeBB+8*Pawn], rcx; popcnt counts the number of pawns  somehow, qword[rbp+Pos.typeBB+8*Pawn] looks like number of pawns, this is stored in r9, no idea what individual terms in brackets mean 
      movzx   edx, byte[rdi+PawnEntry.asymmetry]; this is the term with asymmetry, written in edx
    lea   edx, [rdx+r9-15]; this adds asymmetry + pawns - 15, no idea what is rdx ?
    shl   edx, 3; this shifts edx 3 places to the left, probably multiplies edx (the whole sum) by 8
    lea   r9d, [rdx+4*r9]; this multiplies the thing stored in r9 (pawns) by four and adds it to  8*(asy+pawns-15) in r9d
; r9d = 8*(asy+pawns-15)+4*pawns
      movsx   r10d, si; moves score from esi (si?) to r10d

In SF, we have 8 (asymmetry + kingDistance - 15) + 12 pawns; So, this must not be pawns, but kingDistance. And it is not 4 pawns but 12 pawns. Confusion and panic :(

sf-x commented 7 years ago

popcnt "return the count of number of bits set to 1" I don't understand what is the use of that count

Well, you do understand what's a bitboard? It's a 64-bit (for chess) value, each bit corresponds to a square on the board. Example: A pawn bitboard has a bit set to 1 if a pawn is on the corresponding square, to 0 otherwise. But I'm not sure if you have a pawn bitboard or white pawn bitboard, or black pawn bitboard there.

lantonov commented 7 years ago

So Pos.typeBB is the bitboard, something like 0000000000000100000000000000000001000001000001000000000000000000

lantonov commented 7 years ago

Making analogy with other bracketed terms after perusing the code, in

         qword[rbp+Pos.typeBB+8*Pawn]

is quadword (64 bits) somehow formed by adding rbp (the address of the bitboard) + Pos.typeBB (the bitboard itself; the 0s and 1s above) + 8 Pawn (this is probably a value that indicates the type of the bitboard). 8 Pawn is probably all pawns. I see in the code things like

    mov   rax, qword[rbp+Pos.typeBB+8*Black]
    and   rax, qword[rbp+Pos.typeBB+8*King]

which is probably the bitboard for the Black King (logical and)

sf-x commented 7 years ago

is quadword (64 bits) somehow formed by adding rbp (the address of the bitboard) + Pos.typeBB (the bitboard itself; the 0s and 1s above) + 8 * Pawn (this is probably a value that indicates the type of the bitboard).

No. IIRC, brackets denote value at memory address inside the brackets. So, I guess, rbp points to some structure, Pos.typeBB is the offset of bitboard array inside the structure, 8*Pawn is the offset from the beginning of the array (the 8 is the size of bitboard in bytes), and qword[rbp+Pos.typeBB+8*Pawn] would be the actual bitboard.

lantonov commented 7 years ago

Could be. In any case, it's beyond me. Maybe I can understand something with examples. It's very foggy to me now.

sf-x commented 7 years ago

In SF, we have 8 (asymmetry + kingDistance - 15) + 12 pawns; So, this must not be pawns, but kingDistance. And it is not 4 pawns but 12 pawns. Confusion and panic :(

Please switch panic OFF and consider that you can represent the above as 8 * (asymmetry + pawns - 15) + 4 * pawns + 8 * kingDistance

lantonov commented 7 years ago

Thanks, this is certainly comforting to know. Now that the operations are almost clear, we reach to the defining part:

  const Bitboard QueenSide   = FileABB | FileBBB | FileCBB | FileDBB;
  const Bitboard KingSide    = FileEBB | FileFBB | FileGBB | FileHBB;

and

bool bothFlanks = (pos.pieces(PAWN) & QueenSide) && (pos.pieces(PAWN) & KingSide);

By analogy with others, I guess that the first 2 would be:

QueenSide       equ (FileABB or FileBBB or FileCBB or FileDBB)
KingSide        equ (FileEBB or FileFBB or FileGBB or FileHBB)

pos.pieces(PAWN) is qword[rbp+Pos.typeBB+8*Pawn] (?)

tthsqe12 commented 7 years ago

you will find the latest changes on my fork. However, I don't like this whole stretch of code so I will probably clean in up (make it faster) soon.

Note that there is a branch in the code to handle the bool 'bothFlanks' and yes to pos.pieces(PAWN) is qword[rbp+Pos.typeBB+8*Pawn]

lantonov commented 7 years ago

Thanks, committed to master and executables ready.