// File: /workspace/github_cpp_makefile_star2_O2/wrighteagle2d[P]wrighteaglebase/Debug/../src/InterceptInfo.cpp
// Function: InterceptInfo::CalcTightInterception(BallState const&, PlayerInterceptInfo*, bool)
void InterceptInfo::CalcTightInterception(const BallState &ball,
                                          PlayerInterceptInfo *pInfo,
                                          bool can_inverse) {
  CalcIdealInterception(
      ball, pInfo,
      pInfo->mpPlayer->GetKickableArea()); // TODO: 改成从外面传进来 buffer

  const int idle_cycle = pInfo->mpPlayer->GetIdleCycle();

  //根据go_to_point模型修正
  if (pInfo->solution.interc == 1) {
    int cycle_sup = pInfo->mInterCycle[0];
    int cycle_inf = MobileState::Predictor::MAX_STEP;
    for (int i = cycle_sup; i <= cycle_inf; ++i) {
      int n = Dasher::instance().CycleNeedToPoint(
                  *(pInfo->mpPlayer), ball.GetPredictedPos(i), can_inverse) +
              idle_cycle;
      if (n <= i) { // n以后完全可截
        break;
      }
      pInfo->mInterCycle[0]++;
    }
  } else { // 3
    int cycle_sup = pInfo->mInterCycle[0];
    int cycle_inf = pInfo->mInterCycle[1];
    for (int i = cycle_sup; i <= cycle_inf; ++i) {
      int n = Dasher::instance().CycleNeedToPoint(
                  *(pInfo->mpPlayer), ball.GetPredictedPos(i), can_inverse) +
              idle_cycle;
      if (n <= i) {
        break;
      }
      pInfo->mInterCycle[0]++;
    }
    if (pInfo->mInterCycle[0] <= pInfo->mInterCycle[1]) {
      cycle_sup = pInfo->mInterCycle[0];
      cycle_inf = pInfo->mInterCycle[1];
      for (int i = cycle_inf; i >= cycle_sup; --i) {
        int n = Dasher::instance().CycleNeedToPoint(
                    *(pInfo->mpPlayer), ball.GetPredictedPos(i), can_inverse) +
                idle_cycle;
        if (n <= i) {
          break;
        }
        pInfo->mInterCycle[1]--;
      }
      if (pInfo->mInterCycle[0] > pInfo->mInterCycle[1]) { //窗口收缩成点
        pInfo->solution.interc = 1;
      }
    } else {
      pInfo->solution.interc = 1;
    }

    cycle_sup = pInfo->mInterCycle[2];
    cycle_inf = MobileState::Predictor::MAX_STEP;
    for (int i = cycle_sup; i <= cycle_inf; ++i) {
      int n = Dasher::instance().CycleNeedToPoint(
                  *(pInfo->mpPlayer), ball.GetPredictedPos(i), can_inverse) +
              idle_cycle;
      if (n <= i) { // n以后完全可截
        break;
      }
      pInfo->mInterCycle[2]++;
    }

    if (pInfo->solution.interc == 1) {
      pInfo->mInterCycle[0] = pInfo->mInterCycle[2];
    }
  }

  AnalyseInterceptSolution(ball, pInfo);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r14d
movq %rsi, %rbx
movq %rdi, %r15
movq 0x60(%rsi), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq %r15, -0x38(%rbp)
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x24bb2
movq 0x60(%rbx), %rax
movl 0x124(%rax), %ecx
movl 0x68(%rbx), %r12d
addl 0xc8(%rax), %ecx
movl %ecx, -0x2c(%rbp)
cmpl $0x1, 0x4(%rbx)
jne 0x24a08
movzbl %r14b, %r15d
cmpl $0x32, %r12d
jg 0x24b1d
callq 0x1a77c
movq %rax, %r13
movq 0x60(%rbx), %r14
movq -0x38(%rbp), %rdi
movl %r12d, %esi
callq 0xd4c0
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
movq %r13, %rdi
movq %r14, %rsi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0x1bde8
addl -0x2c(%rbp), %eax
cmpl %r12d, %eax
jle 0x24b1d
incl 0x68(%rbx)
incl %r12d
jmp 0x249b9
movl 0x6c(%rbx), %r15d
movzbl %r14b, %eax
movl %eax, -0x30(%rbp)
movl %r12d, %r13d
cmpl %r15d, %r13d
jg 0x24a64
callq 0x1a77c
movq %rax, %r14
movq 0x60(%rbx), %r12
movq -0x38(%rbp), %rdi
movl %r13d, %esi
callq 0xd4c0
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
movq %r14, %rdi
movq %r12, %rsi
movl -0x30(%rbp), %edx
xorl %ecx, %ecx
callq 0x1bde8
addl -0x2c(%rbp), %eax
movl 0x68(%rbx), %r12d
cmpl %r13d, %eax
jle 0x24a64
incl %r12d
movl %r12d, 0x68(%rbx)
incl %r13d
jmp 0x24a16
movl 0x6c(%rbx), %ecx
cmpl %ecx, %r12d
jg 0x24abf
movl %ecx, %r13d
cmpl %r12d, %r13d
jl 0x24aba
callq 0x1a77c
movq %rax, %r14
movq 0x60(%rbx), %r15
movq -0x38(%rbp), %rdi
movl %r13d, %esi
callq 0xd4c0
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
movq %r14, %rdi
movq %r15, %rsi
movl -0x30(%rbp), %edx
xorl %ecx, %ecx
callq 0x1bde8
addl -0x2c(%rbp), %eax
movl 0x6c(%rbx), %ecx
cmpl %r13d, %eax
jle 0x24aba
decl %ecx
movl %ecx, 0x6c(%rbx)
decl %r13d
jmp 0x24a6f
cmpl %ecx, 0x68(%rbx)
jle 0x24ac6
movl $0x1, 0x4(%rbx)
movl 0x70(%rbx), %r12d
cmpl $0x32, %r12d
jg 0x24b11
callq 0x1a77c
movq %rax, %r14
movq 0x60(%rbx), %r15
movq -0x38(%rbp), %rdi
movl %r12d, %esi
callq 0xd4c0
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
movq %r14, %rdi
movq %r15, %rsi
movl -0x30(%rbp), %edx
xorl %ecx, %ecx
callq 0x1bde8
addl -0x2c(%rbp), %eax
cmpl %r12d, %eax
jle 0x24b11
incl 0x70(%rbx)
incl %r12d
jmp 0x24aca
cmpl $0x1, 0x4(%rbx)
jne 0x24b1d
movl 0x70(%rbx), %eax
movl %eax, 0x68(%rbx)
movq -0x38(%rbp), %rdi
movq %rbx, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x24b38
nop