// File: ATOMIC-LICHESS[P]ATOMKRAFT/movepick.cpp
// Function: MovePicker::MovePicker(Position const&, Move, Depth, History const&, SearchStack*, Value)
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
                       SearchStack* ss, Value beta) : pos(p), H(h) {
  int searchTT = ttm;
  ttMoves[0].move = ttm;
  
  //NEW badCaptureThreshold = PawnValueMidgame;
  badCaptureThreshold = 0;
  
  badCaptures = moves + MAX_MOVES;

  assert(d > DEPTH_ZERO);

  pinned = p.pinned_pieces(pos.side_to_move());

  if (p.in_check())
  {
      ttMoves[1].move = killers[0].move = killers[1].move = MOVE_NONE;
      phasePtr = EvasionTable;
  }
  else
  {
      ttMoves[1].move = (ss->mateKiller == ttm) ? MOVE_NONE : ss->mateKiller;
      searchTT |= ttMoves[1].move;
      killers[0].move = ss->killers[0];
      killers[1].move = ss->killers[1];

      // Consider sligtly negative captures as good if at low
      // depth and far from beta.
      if (ss && ss->eval < beta - PawnValueMidgame && d < 3 * ONE_PLY) { 
    	  //NEW badCaptureThreshold = 0;
    	  badCaptureThreshold = -PawnValueMidgame;
      }

      phasePtr = MainSearchTable;
  }

  phasePtr += int(!searchTT) - 1;
  go_next_phase();
}

// Assembly:
subq $0x58, %rsp
movl 0x60(%rsp), %eax
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movl %edx, 0x44(%rsp)
movl %ecx, 0x40(%rsp)
movq %r8, 0x38(%rsp)
movq %r9, 0x30(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x48(%rsp), %rcx
movq %rcx, (%rax)
movq 0x38(%rsp), %rcx
movq %rcx, 0x8(%rax)
movl 0x44(%rsp), %ecx
movl %ecx, 0x2c(%rsp)
movl 0x44(%rsp), %ecx
movl %ecx, 0x18(%rax)
movl $0x0, 0x38(%rax)
movq %rax, %rcx
addq $0x68, %rcx
addq $0x800, %rcx            # imm = 0x800
movq %rcx, 0x60(%rax)
movq 0x48(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movq (%rax), %rdi
callq 0xf5d0
movq 0x18(%rsp), %rdi
movl %eax, %esi
callq 0x38990
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x48(%rsp), %rdi
callq 0x2e600
testb $0x1, %al
jne 0x33bf1
jmp 0x33c1b
movq 0x20(%rsp), %rax
movl $0x0, 0x30(%rax)
movl $0x0, 0x28(%rax)
movl $0x0, 0x20(%rax)
leaq 0x26ef6(%rip), %rcx     # 0x5ab08
movq %rcx, 0x40(%rax)
jmp 0x33ce3
movq 0x30(%rsp), %rax
movl 0x8(%rax), %eax
cmpl 0x44(%rsp), %eax
jne 0x33c31
xorl %eax, %eax
movl %eax, 0x14(%rsp)
jmp 0x33c3d
movq 0x30(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x14(%rsp)
movq 0x20(%rsp), %rax
movl 0x14(%rsp), %ecx
movl %ecx, 0x20(%rax)
movl 0x20(%rax), %ecx
orl 0x2c(%rsp), %ecx
movl %ecx, 0x2c(%rsp)
movq 0x30(%rsp), %rcx
movl 0x14(%rcx), %ecx
movl %ecx, 0x28(%rax)
movq 0x30(%rsp), %rcx
movl 0x18(%rcx), %ecx
movl %ecx, 0x30(%rax)
cmpq $0x0, 0x30(%rsp)
je 0x33cd3
movq 0x30(%rsp), %rax
movl 0x20(%rax), %eax
movl %eax, 0x10(%rsp)
movl 0x60(%rsp), %edi
leaq 0x388cf(%rip), %rax     # 0x6c558
movl (%rax), %esi
callq 0x1b300
movl %eax, %ecx
movl 0x10(%rsp), %eax
cmpl %ecx, %eax
jge 0x33cd3
movl 0x40(%rsp), %eax
movl %eax, 0xc(%rsp)
movl $0x3, %edi
movl $0x2, %esi
callq 0x34660
movl %eax, %ecx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jge 0x33cd3
leaq 0x38896(%rip), %rax     # 0x6c558
movl (%rax), %edi
callq 0x1b2b0
movl %eax, %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x38(%rax)
movq 0x20(%rsp), %rax
leaq 0x26e61(%rip), %rcx     # 0x5ab40
movq %rcx, 0x40(%rax)
movq 0x20(%rsp), %rdi
cmpl $0x0, 0x2c(%rsp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %ecx
subl $0x1, %ecx
movq 0x40(%rdi), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x40(%rdi)
callq 0x33d20
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)