// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/position.cpp
// Function: Position::do_capture_move(unsigned long&, PieceType, Color, Square, Square, bool)
NEW // parameter: Square from
void Position::do_capture_move(Key& key, PieceType capture, Color them, Square to, Square from, bool ep) {

	STARTNEW
#ifndef NDEBUG
	if (capture == KING || type_of_piece_on(from) == KING) {
		cout << "them: " << them << endl;
		cout << "to: " << to << endl;
		cout << "from: " << from << endl;
		cout << "ep: " << ep << endl;
		cout << "capture: " << capture << endl;
		print_debuginfo(*this);
	}
#endif
	ENDNEW

	
	NEW // captures performed by the king are not allowed
	NEW assert(type_of_piece_on(from) != KING);
    assert(capture != KING);

    Square capsq = to;
    
    STARTNEW
    /*
     * gather information about all exploded pieces and stores them in st->expl
     * additionally remove the pieces from relevant lists and bitboards
     * we don't remove the central capture, this is done in the original code
     */ 
    int explCount = 0;
   
    // gather information about the first obligatory capture
    // the actual capture is done later
    Square explSquare = explSq[to].square[0];
    Piece explPiece = board[explSquare];
    Color explColor;
    PieceType explPieceType;
	st->expl.piece[0] = explPiece;
	st->expl.square[0] = explSquare;
	++explCount;
	
	// now capture the other pieces
    for (int k = 1; k < explSq[to].size; ++k) {
    	explSquare = explSq[to].square[k];
    	explPiece = board[explSquare];
    	
    	// skip if we are about to remove the attacking piece
    	if (explSquare == from) continue;
    	
    	if (explPiece != PIECE_NONE && explPiece != WP && explPiece != BP) {
    		// gather information
    		st->expl.piece[explCount] = explPiece;
    		st->expl.square[explCount] = explSquare;
    		explColor = color_of_piece(explPiece);
    		explPieceType = type_of_piece(explPiece);
    		++explCount;
    		
    		// do the capture
    		remove_piece(key, explColor, explSquare, explPieceType);
    		
    	}
    }
    st->expl.size = explCount;
    ENDNEW

    // If the captured piece was a pawn, update pawn hash key,
    // otherwise update non-pawn material.
    if (capture == PAWN)
    {
        if (ep) // en passant ?
        {
            capsq = (them == BLACK)? (to - DELTA_N) : (to - DELTA_S);

            assert(to == st->epSquare);
            assert(relative_rank(opposite_color(them), to) == RANK_6);
            assert(piece_on(to) == PIECE_NONE);
            assert(piece_on(capsq) == make_piece(them, PAWN));

            board[capsq] = PIECE_NONE;
        }
        st->pawnKey ^= zobrist[them][PAWN][capsq];
    } else {
        st->npMaterial[them] -= PieceValueMidgame[capture];
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, %r13d
movq %rdi, %rbx
movslq %r8d, %r10
imulq $0x4c, %r10, %r9
leaq 0x1d316(%rip), %rbp     # 0x3d490
movslq (%rbp,%r9), %rdi
movl (%rbx,%rdi,4), %r11d
movq 0x1938(%rbx), %rax
movl %r11d, 0x6c(%rax)
movl %edi, 0x48(%rax)
movl 0x48(%rbp,%r9), %edi
movl $0x1, %r15d
cmpl $0x2, %edi
jl 0x20242
movq %r8, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movl %edx, 0xc(%rsp)
movq %r10, 0x20(%rsp)
addq %r9, %rbp
movl $0x1, %r15d
movl $0x1, %r12d
movl $0x10202, %edx          # imm = 0x10202
movslq (%rbp,%r12,4), %rcx
cmpl %r13d, %ecx
je 0x2021d
movl (%rbx,%rcx,4), %r8d
cmpl $0x10, %r8d
ja 0x201e6
btl %r8d, %edx
jb 0x2021d
movq 0x1938(%rbx), %rax
movslq %r15d, %r15
movl %r8d, 0x6c(%rax,%r15,4)
movl %ecx, 0x48(%rax,%r15,4)
movl %r8d, %edx
sarl $0x3, %edx
andl $0x7, %r8d
incl %r15d
movq %rbx, %rdi
movq %rsi, %r14
callq 0x20396
movl $0x10202, %edx          # imm = 0x10202
movq %r14, %rsi
movl 0x48(%rbp), %edi
incq %r12
movslq %edi, %rax
cmpq %rax, %r12
jl 0x201cc
movq 0x1938(%rbx), %rax
movq 0x20(%rsp), %r10
movl 0xc(%rsp), %edx
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %r8
movl %r15d, 0x90(%rax)
cmpl $0x1, %edx
jne 0x20299
cmpb $0x0, 0x60(%rsp)
je 0x20272
xorl %edi, %edi
cmpl $0x1, %ecx
setne %dil
shll $0x4, %edi
addl %r8d, %edi
addl $-0x8, %edi
movslq %edi, %r10
movl $0x10, (%rbx,%r10,4)
movl %ecx, %r11d
movq %r11, %r8
shlq $0xc, %r8
leaq 0x398d0d(%rip), %rdi    # 0x3b8f90
addq %r8, %rdi
movq 0x200(%rdi,%r10,8), %rdi
xorq %rdi, (%rax)
movl $0x1, %r14d
jmp 0x202af
movl %edx, %r14d
leaq 0x39bf7d(%rip), %rdi    # 0x3bc220
movl (%rdi,%r14,4), %edi
movl %ecx, %r11d
subl %edi, 0x28(%rax,%r11,4)
leaq 0xf90fa(%rip), %r8      # 0x1193b0
movq (%r8,%r10,8), %rdi
andq %rdi, 0x140(%rbx,%r11,8)
movq (%r8,%r10,8), %rdi
andq %rdi, 0x100(%rbx,%r14,8)
movq (%r8,%r10,8), %rdi
andq %rdi, 0x100(%rbx)
movq %r11, %r8
shlq $0xc, %r8
leaq 0x398ca9(%rip), %rdi    # 0x3b8f90
addq %r8, %rdi
movq %r14, %r15
shlq $0x9, %r15
addq %rdi, %r15
movq (%r15,%r10,8), %rdi
xorq %rdi, (%rsi)
shll $0x3, %ecx
orl %edx, %ecx
shlq $0x8, %rcx
leaq 0x39af15(%rip), %rdi    # 0x3bb220
addq %rcx, %rdi
movl (%rdi,%r10,4), %edi
subl %edi, 0x24(%rax)
movq %r11, %rdi
shlq $0x5, %rdi
addq %rbx, %rdi
movslq 0x150(%rdi,%r14,4), %r8
leaq -0x1(%r8), %r9
movl %r9d, 0x150(%rdi,%r14,4)
movq -0x8(%r15,%r8,8), %rsi
xorq %rsi, 0x8(%rax)
shlq $0x9, %r11
addq %rbx, %r11
movq %r14, %rsi
shlq $0x6, %rsi
addq %r11, %rsi
movslq 0x18c(%rsi,%r8,4), %rdx
movslq 0x590(%rbx,%r10,4), %r8
movl %r8d, 0x590(%rbx,%rdx,4)
movl %edx, 0x190(%rsi,%r8,4)
movslq 0x150(%rdi,%r14,4), %rcx
movl $0x40, 0x190(%rsi,%rcx,4)
movl $0x0, 0x14(%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq