// File: /workspace/github_cpp_makefile_star2_O1/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, %r15d
movq %rsi, %rbx
movq %rdi, %r14
movq 0x60(%rsi), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq %r14, -0x38(%rbp)
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2b7c2
movq 0x60(%rbx), %rax
movl 0x124(%rax), %r14d
movl 0x68(%rbx), %r12d
addl 0xc8(%rax), %r14d
cmpl $0x1, 0x4(%rbx)
jne 0x2b5bf
cmpl $0x32, %r12d
jg 0x2b6e8
movzbl %r15b, %eax
movl %eax, -0x2c(%rbp)
callq 0x1f5e8
movq %rax, %r13
movq 0x60(%rbx), %r15
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rdi
movl %r12d, %esi
callq 0x22890
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
movq %r13, %rdi
movq %r15, %rsi
movl -0x2c(%rbp), %edx
xorl %ecx, %ecx
callq 0x21622
addl %r14d, %eax
cmpl %r12d, %eax
jle 0x2b6e8
incl 0x68(%rbx)
incl %r12d
cmpl $0x33, %r12d
jne 0x2b56d
jmp 0x2b6e8
movl 0x6c(%rbx), %ecx
movzbl %r15b, %eax
movl %eax, -0x2c(%rbp)
movl %ecx, -0x30(%rbp)
cmpl %ecx, %r12d
jg 0x2b61d
incl -0x30(%rbp)
callq 0x1f5e8
movq %rax, %r13
movq 0x60(%rbx), %r15
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rdi
movl %r12d, %esi
callq 0x22890
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
movq %r13, %rdi
movq %r15, %rsi
movl -0x2c(%rbp), %edx
xorl %ecx, %ecx
callq 0x21622
addl %r14d, %eax
cmpl %r12d, %eax
jle 0x2b61d
incl 0x68(%rbx)
incl %r12d
cmpl %r12d, -0x30(%rbp)
jne 0x2b5d4
movl 0x68(%rbx), %eax
movl 0x6c(%rbx), %r12d
movl %eax, -0x30(%rbp)
cmpl %r12d, %eax
jg 0x2b682
callq 0x1f5e8
movq %rax, %r15
movq 0x60(%rbx), %r13
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rdi
movl %r12d, %esi
callq 0x22890
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
movq %r15, %rdi
movq %r13, %rsi
movl -0x2c(%rbp), %edx
xorl %ecx, %ecx
callq 0x21622
addl %r14d, %eax
cmpl %r12d, %eax
jle 0x2b67a
decl 0x6c(%rbx)
leal -0x1(%r12), %eax
cmpl -0x30(%rbp), %r12d
movl %eax, %r12d
jg 0x2b62c
movl 0x68(%rbx), %eax
cmpl 0x6c(%rbx), %eax
jle 0x2b689
movl $0x1, 0x4(%rbx)
movl 0x70(%rbx), %r12d
cmpl $0x32, %r12d
jg 0x2b6dc
callq 0x1f5e8
movq %rax, %r15
movq 0x60(%rbx), %r13
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rdi
movl %r12d, %esi
callq 0x22890
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
movq %r15, %rdi
movq %r13, %rsi
movl -0x2c(%rbp), %edx
xorl %ecx, %ecx
callq 0x21622
addl %r14d, %eax
cmpl %r12d, %eax
jle 0x2b6dc
incl 0x70(%rbx)
incl %r12d
cmpl $0x33, %r12d
jne 0x2b693
cmpl $0x1, 0x4(%rbx)
jne 0x2b6e8
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 0x2b702