// File: /workspace/github_cpp_makefile_star2_O2/wrighteagle2d[P]wrighteaglebase/Debug/../src/Kicker.cpp
// Function: Kicker::ComputeUtilityTable()
void Kicker::ComputeUtilityTable() {
  Assert(Parser::IsPlayerTypesReady());

  mInput.mPlayerType = 0; //离线计算只考虑0号类型
  for (int k = 0; k < POINTS_NUM; ++k) {
    mKickRate[k] = GetKickRate(mPoint[k], mInput.mPlayerType);
    mMaxAccel[k] = ServerParam::instance().maxPower() * mKickRate[k];
  }

  AngleDeg kick_angle = 0.0; //踢球角度
  Vector ball_vel = Vector(0.0, 0.0);
  Vector ball_next = Vector(0.0, 0.0);
  double max_speed = 0.0;

  for (int v = 0; v < 3; ++v) // 3次迭代，分别算v[0], v[1], v[2]
  {
    for (int i = 0; i < 36; ++i) //踢球角度
    {
      kick_angle = STEP_KICK_ANGLE * i;

      for (int j = 0; j < POINTS_NUM; ++j) //初始位置，即第1脚kick前的位置
      {
        for (int k = 0; k < POINTS_NUM; ++k) //第1脚kick后的位置
        {
          ball_vel =
              (mPoint[k] - mPoint[j]) * ServerParam::instance().ballDecay();

          if (v == 0) // v[0]直接算即可
          {
            mKickerValue[v][i][j][k] =
                (float)GetOneKickMaxSpeed(ball_vel, kick_angle, mMaxAccel[k]);
          } else // v[1]和v[2]要迭代
          {
            max_speed = 0.0;
            ball_next = mPoint[k] + ball_vel;

            for (int l = 0; l < POINTS_NUM; ++l) //从j踢到k，再踢到l
            {
              if (mPoint[l].Dist(ball_next) <
                  mMaxAccel[k]) //保证理论上可以从k踢到l
              {
                max_speed =
                    Max(max_speed, (double)mKickerValue[v - 1][i][k][l]);
              }
            }

            mKickerValue[v][i][j][k] = (float)max_speed;
          }
        }
      }
    }
  }

  //写文件
  std::ofstream out_file("kicker_value", std::ios::binary);
  if (!out_file) {
    PRINT_ERROR("open file error");
    return;
  }
  out_file.write((char *)mKickerValue, sizeof(mKickerValue));
  out_file.close();

  std::cerr << "compute kicker value over ..." << std::endl;
  exit(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %rdi, %rbx
andl $0x0, 0x2b4580(%rdi)
leaq 0x48(%rdi), %rdx
leaq 0x2b4870(%rdi), %rax
movq %rax, -0x48(%rbp)
movl $0x568bd, %r15d         # imm = 0x568BD
movq %rdx, %r14
cmpq $0x5690e, %r15          # imm = 0x5690E
je 0x29411
movl 0x2b4580(%rbx), %esi
movq %r14, %rdi
movq %rdx, %r12
callq 0xd05c
movsd %xmm0, (%rbx,%r15,8)
callq 0x3db2c
movq %r12, %rdx
movsd 0x3130(%rax), %xmm0
mulsd (%rbx,%r15,8), %xmm0
movsd %xmm0, 0x288(%rbx,%r15,8)
incq %r15
addq $0x10, %r14
jmp 0x293c8
leaq -0x60(%rbp), %rax
andq $0x0, (%rax)
leaq 0x558(%rbx), %rax
movq %rax, -0x30(%rbp)
xorpd %xmm0, %xmm0
leaq -0x70(%rbp), %rax
movapd %xmm0, (%rax)
leaq -0xe6538(%rbx), %rax
movq %rax, -0x38(%rbp)
xorl %eax, %eax
cmpq $0x3, %rax
je 0x29635
movq -0x38(%rbp), %rcx
movq %rcx, -0x40(%rbp)
xorl %ecx, %ecx
movq %rax, -0x50(%rbp)
cmpq $0x24, %rcx
je 0x29625
imull $0xa, %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x60(%rbp)
imulq $0x6684, %rcx, %rsi     # imm = 0x6684
movq -0x30(%rbp), %rax
movq %rsi, -0x88(%rbp)
addq %rsi, %rax
movq %rax, -0x80(%rbp)
xorl %esi, %esi
movq %rcx, -0x78(%rbp)
cmpq $0x51, %rsi
je 0x29611
movq %rsi, %rax
shlq $0x4, %rax
addq %rdx, %rax
movq %rax, -0x90(%rbp)
movq -0x40(%rbp), %r15
xorl %r13d, %r13d
movq %rsi, -0x58(%rbp)
cmpq $0x51, %r13
je 0x29605
movq %r13, %r12
shlq $0x4, %r12
movsd (%rdx,%r12), %xmm0
movsd 0x8(%rdx,%r12), %xmm1
movq -0x90(%rbp), %rax
subsd (%rax), %xmm0
movsd %xmm0, -0xa0(%rbp)
subsd 0x8(%rax), %xmm1
movsd %xmm1, -0x98(%rbp)
movq %rdx, %r14
callq 0x3db2c
movsd -0x98(%rbp), %xmm5
movsd -0xa0(%rbp), %xmm4
movsd 0x30e0(%rax), %xmm0
mulsd %xmm0, %xmm4
mulsd %xmm0, %xmm5
movsd %xmm4, -0x70(%rbp)
movsd %xmm5, -0x68(%rbp)
movq -0x50(%rbp), %rcx
testq %rcx, %rcx
je 0x295c2
addq %r14, %r12
addsd (%r12), %xmm4
addsd 0x8(%r12), %xmm5
movq -0x48(%rbp), %rax
movsd (%rax,%r13,8), %xmm0
xorpd %xmm1, %xmm1
xorl %eax, %eax
movq %r14, %rdx
movq -0x58(%rbp), %rsi
cmpq $0x144, %rax            # imm = 0x144
je 0x2959a
movsd 0x48(%rbx,%rax,4), %xmm2
subsd %xmm4, %xmm2
movsd 0x50(%rbx,%rax,4), %xmm3
subsd %xmm5, %xmm3
mulsd %xmm3, %xmm3
mulsd %xmm2, %xmm2
addsd %xmm3, %xmm2
sqrtsd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
jbe 0x29594
cvtss2sd (%r15,%rax), %xmm2
maxsd %xmm1, %xmm2
movapd %xmm2, %xmm1
addq $0x4, %rax
jmp 0x29554
cvtsd2ss %xmm1, %xmm0
imulq $0xe6a90, %rcx, %rax    # imm = 0xE6A90
addq -0x30(%rbp), %rax
imulq $0x144, %rsi, %rcx      # imm = 0x144
addq -0x88(%rbp), %rcx
addq %rax, %rcx
movss %xmm0, (%rcx,%r13,4)
jmp 0x295f6
movq -0x48(%rbp), %rax
leaq (%rax,%r13,8), %rcx
movq %rbx, %rdi
leaq -0x70(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x2a844
cvtsd2ss %xmm0, %xmm0
movq -0x58(%rbp), %rsi
imulq $0x144, %rsi, %rax      # imm = 0x144
addq -0x80(%rbp), %rax
movss %xmm0, (%rax,%r13,4)
movq %r14, %rdx
incq %r13
addq $0x144, %r15            # imm = 0x144
jmp 0x294b0
incq %rsi
movq -0x78(%rbp), %rcx
jmp 0x2948a
incq %rcx
addq $0x6684, -0x40(%rbp)    # imm = 0x6684
movq -0x50(%rbp), %rax
jmp 0x29455
incq %rax
addq $0xe6a90, -0x38(%rbp)   # imm = 0xE6A90
jmp 0x2943d
leaq 0x2f2b9(%rip), %rsi     # 0x588f5
leaq -0x2a0(%rbp), %rbx
pushq $0x4
popq %rdx
movq %rbx, %rdi
callq 0x9520
movq (%rbx), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x280(%rbp,%rax)
je 0x296d2
movq 0x4d98a(%rip), %rdi     # 0x76ff0
leaq 0x2f295(%rip), %rsi     # 0x58902
callq 0x94b0
leaq 0x31af9(%rip), %rsi     # 0x5b172
movq %rax, %rdi
callq 0x94b0
movq %rax, %rdi
movl $0x1f8, %esi            # imm = 0x1F8
callq 0x9890
leaq 0x2fd8a(%rip), %rsi     # 0x5941f
movq %rax, %rdi
callq 0x94b0
leaq 0x2f270(%rip), %rsi     # 0x58914
movq %rax, %rdi
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
leaq -0x2a0(%rbp), %rdi
callq 0x9720
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x2a0(%rbp), %rdi
movl $0x2b3fb0, %edx         # imm = 0x2B3FB0
movq -0x30(%rbp), %rsi
callq 0x9650
leaq -0x2a0(%rbp), %rdi
callq 0x96e0
movq 0x4d8f6(%rip), %rdi     # 0x76ff0
leaq 0x2f223(%rip), %rsi     # 0x58924
callq 0x94b0
movq %rax, %rdi
callq 0x99e8
xorl %edi, %edi
callq 0x95d0
movq %rax, %rbx
leaq -0x2a0(%rbp), %rdi
callq 0x9720
movq %rbx, %rdi
callq 0x98b0