// File: /workspace/github_cpp_makefile_star2_O3/wrighteagle2d[P]wrighteaglebase/Debug/../src/Trainer.cpp
// Function: Trainer::ReadRcgFile()
bool Trainer::ReadRcgFile() {
  // TODO 读取之前的PlayMode
  string line;
  const char *buf = 0;
  ifstream fin(mTrainRcg);
  int time = 0, n_read = 0;

  const int begin_time = mTrainTime - mInitialTime;
  const int end_time = mTrainTime;

  ServerPlayMode server_playmode = SPM_PlayOn;

  while (1) {
    vector<PlayerState> ps;
    pair<Vector, Vector> bs;

    bool read = false;

    while (getline(fin, line)) {
      read = true;
      if (!line.compare(0, 5, "(show")) {
        if (sscanf(line.c_str(), "(show %d %n", &time, &n_read) != 1) {
          PRINT_ERROR("error time info:" << line);
          return false;
        }

        if (time >= begin_time) {
          buf = line.c_str();
          buf += n_read;
          break;
        }
      } else if (line.compare(0, 10, "(playmode ") == 0) {
        int time = 0;
        char pm_string[32];

        if (std::sscanf(line.c_str(), " (playmode %d %31[^)] ) ", &time,
                        pm_string) != 2) {
          std::cerr << "error: "
                    << "Illegal playmode line. \"" << line << "\"" << std::endl;
          return false;
        }

        server_playmode =
            ServerPlayModeMap::instance().GetServerPlayMode(pm_string);
      }
    }

    if (!read) {
      break;
    }

    mServerPlayModeList.push_back(server_playmode);

    float bx, by, bvx, bvy;

    if (buf == 0) //没有找到对应周期
    {
      return false;
    }

    {
      if (sscanf(buf, " ((b) %f %f %f %f) %n", &bx, &by, &bvx, &bvy, &n_read) !=
          4) {
        PRINT_ERROR("error ball info:" << line);
        return false;
      }
      buf += n_read;
      bs.first = Vector(bx, by);
      bs.second = Vector(bvx, bvy);
      bs.second /= 0.94;
      bs.first -= bs.second; //这是因为Server接到后会模拟一周期
    }

    // players
    char side;
    short unum;
    short type;
    int state;
    float x, y, vx, vy, body, neck;
    for (int i = 0; i < ServerParam::TEAM_SIZE * 2; ++i) {
      if (*buf == '\0' || *buf == ')')
        break;

      if (sscanf(buf, " ((%c %hd) %hd %x %f %f %f %f %f %f %n", &side, &unum,
                 &type, &state, &x, &y, &vx, &vy, &body, &neck,
                 &n_read) != 10) {
        PRINT_ERROR("error player info:" << buf);
        return false;
      }
      buf += n_read;

      int idx = unum - 1;
      if (side == 'r')
        idx += ServerParam::TEAM_SIZE;
      if (idx < 0 || ServerParam::TEAM_SIZE * 2 <= idx) {
        PRINT_ERROR("error player info:" << buf);
        return false;
      }

      if (side == 'r')
        unum = -unum;

      //对球员的微调安排在开场前，而不是建立前，因为牵涉到Server发来的异构
      ps.push_back(
          Trainer::PlayerState(unum, Vector(x, y), Vector(vx, vy), body, type));

      while (strncmp(buf, "((", 2)) {
        buf++;
        if (*buf == '\0')
          break;
      }
    }

    if (ps.size() == 22) {
      mPlayerStatesList.push_back(ps);
      mBallStateList.push_back(bs);
    }

    if (time >= end_time) {
      break;
    }
  }

  Assert(mPlayerStatesList.size() == mBallStateList.size());
  Assert(mPlayerStatesList.size() == mServerPlayModeList.size());

  return !mPlayerStatesList.empty();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x358, %rsp            # imm = 0x358
movq %rdi, %rbx
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0xa0(%rdi), %rsi
leaq -0x378(%rbp), %r13
movq %r13, %rdi
movl $0x8, %edx
callq 0x9920
xorl %eax, %eax
leaq -0x48(%rbp), %rcx
movl %eax, (%rcx)
leaq -0x30(%rbp), %rcx
movl %eax, (%rcx)
movl 0x98(%rbx), %eax
movl %eax, -0x9c(%rbp)
subl 0x138(%rbx), %eax
movl %eax, -0xa8(%rbp)
leaq -0x44(%rbp), %rax
movl $0x3, (%rax)
leaq 0x178(%rbx), %rax
movq %rax, -0x168(%rbp)
leaq 0x1a944(%rip), %rax     # 0x6bf58
movl (%rax), %eax
movq %rax, -0xd0(%rbp)
addl %eax, %eax
leaq 0x120(%rbx), %rcx
movq %rcx, -0x160(%rbp)
movq %rbx, -0x98(%rbp)
leaq 0x160(%rbx), %rcx
movq %rcx, -0x158(%rbp)
cmpl $0x2, %eax
movl $0x1, %ecx
movl %eax, -0xa4(%rbp)
cmovgel %eax, %ecx
movl %ecx, -0xa0(%rbp)
movq $0x0, -0x38(%rbp)
xorpd %xmm0, %xmm0
movapd %xmm0, -0x90(%rbp)
movq $0x0, -0x80(%rbp)
movapd %xmm0, -0x100(%rbp)
movapd %xmm0, -0x110(%rbp)
xorl %ebx, %ebx
movq -0x378(%rbp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x9480
movsbl %al, %edx
movq %r13, %rdi
leaq -0x70(%rbp), %rsi
callq 0x9940
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x517e2
movl $0x5, %edx
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
leaq 0x1b856(%rip), %rcx     # 0x6cf28
callq 0x9650
testl %eax, %eax
je 0x517a4
movl $0xa, %edx
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
leaq 0x19329(%rip), %rcx     # 0x6aa1a
callq 0x9650
movb $0x1, %bl
testl %eax, %eax
jne 0x51687
movl $0x0, -0x40(%rbp)
movq -0x70(%rbp), %rdi
leaq 0x1b83d(%rip), %rsi     # 0x6cf4b
leaq -0x40(%rbp), %rdx
leaq -0x150(%rbp), %rcx
xorl %eax, %eax
callq 0x9490
cmpl $0x2, %eax
jne 0x51c90
callq 0x546f6
movq %rax, %r12
leaq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0x150(%rbp), %r14
movq %r14, %rdi
callq 0x9200
leaq (%rax,%rbp), %rdx
addq $-0x150, %rdx           # imm = 0xFEB0
leaq -0xf0(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x1362e
movq %r12, %rdi
movq %r15, %rsi
callq 0x55982
movl %eax, -0x44(%rbp)
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x51687
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x94e0
jmp 0x51687
movq -0x70(%rbp), %rdi
leaq 0x1b77f(%rip), %rsi     # 0x6cf2e
leaq -0x48(%rbp), %rdx
leaq -0x30(%rbp), %rcx
xorl %eax, %eax
callq 0x9490
cmpl $0x1, %eax
jne 0x51821
movb $0x1, %bl
movl -0xa8(%rbp), %eax
cmpl %eax, -0x48(%rbp)
jl 0x51687
movslq -0x30(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x517f1
movl $0x3, %r15d
testb $0x1, %bl
je 0x51d40
movq -0x98(%rbp), %rcx
movq 0x180(%rcx), %rsi
cmpq 0x188(%rcx), %rsi
je 0x518d2
movl -0x44(%rbp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x180(%rcx)
jmp 0x518e2
movl $0x12, %edx
movq 0x327c3(%rip), %rdi     # 0x83ff0
leaq 0x1b5a6(%rip), %rsi     # 0x6cdda
callq 0x9560
movl $0x1, %edx
movq 0x327ab(%rip), %rdi     # 0x83ff0
leaq 0x1b946(%rip), %rsi     # 0x6d192
callq 0x9560
movq 0x32798(%rip), %rdi     # 0x83ff0
movl $0x204, %esi            # imm = 0x204
callq 0x9880
movq %rax, %r12
movl $0x3, %edx
movq %rax, %rdi
leaq 0x19be3(%rip), %rsi     # 0x6b457
callq 0x9560
movl $0x10, %edx
movq %r12, %rdi
leaq 0x1b6b2(%rip), %rsi     # 0x6cf3a
callq 0x9560
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq %r12, %rdi
callq 0x9560
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x9480
movsbl %al, %esi
movq %r12, %rdi
callq 0x9070
movl $0x1, %r15d
movq %rax, %rdi
callq 0x9330
jmp 0x51d40
movq -0x168(%rbp), %rdi
leaq -0x44(%rbp), %rdx
callq 0x535b2
movl $0x1, %r15d
movq -0x38(%rbp), %rbx
testq %rbx, %rbx
je 0x51bd8
subq $0x8, %rsp
movq %rbx, %rdi
leaq 0x1b682(%rip), %rsi     # 0x6cf85
leaq -0xf0(%rbp), %rdx
leaq -0x40(%rbp), %rcx
leaq -0xc4(%rbp), %r8
leaq -0xc0(%rbp), %r9
xorl %eax, %eax
leaq -0x30(%rbp), %r10
pushq %r10
callq 0x9490
addq $0x10, %rsp
cmpl $0x4, %eax
jne 0x51be5
movslq -0x30(%rbp), %rax
xorps %xmm0, %xmm0
cvtss2sd -0xf0(%rbp), %xmm0
cvtss2sd -0x40(%rbp), %xmm1
cvtss2sd -0xc4(%rbp), %xmm2
addq %rax, %rbx
cvtss2sd -0xc0(%rbp), %xmm3
movsd 0x1a503(%rip), %xmm4    # 0x6be68
divsd %xmm4, %xmm2
movsd %xmm2, -0x100(%rbp)
divsd %xmm4, %xmm3
movsd %xmm3, -0xf8(%rbp)
subsd %xmm2, %xmm0
movsd %xmm0, -0x110(%rbp)
subsd %xmm3, %xmm1
movsd %xmm1, -0x108(%rbp)
cmpl $0x0, -0xd0(%rbp)
movq %rbx, -0x38(%rbp)
jle 0x51b6e
movb (%rbx), %al
xorl %ebx, %ebx
testb %al, %al
je 0x51b6e
movzbl %al, %eax
cmpl $0x29, %eax
je 0x51b6e
subq $0x8, %rsp
movq -0x38(%rbp), %r15
movq %r15, %rdi
leaq 0x1b5dc(%rip), %rsi     # 0x6cfac
leaq -0x29(%rbp), %rdx
leaq -0x3a(%rbp), %rcx
leaq -0x4a(%rbp), %r8
leaq -0x170(%rbp), %r9
xorl %eax, %eax
leaq -0x30(%rbp), %r10
pushq %r10
leaq -0x16c(%rbp), %r10
pushq %r10
leaq -0xac(%rbp), %r10
pushq %r10
leaq -0xb0(%rbp), %r10
pushq %r10
leaq -0xb4(%rbp), %r10
pushq %r10
leaq -0xb8(%rbp), %r10
pushq %r10
leaq -0xbc(%rbp), %r10
pushq %r10
callq 0x9490
addq $0x40, %rsp
cmpl $0xa, %eax
jne 0x51d66
movslq -0x30(%rbp), %rax
addq %rax, %r15
movq %r15, -0x38(%rbp)
movswl -0x3a(%rbp), %eax
movb -0x29(%rbp), %cl
cmpb $0x72, %cl
movl $0x0, %edx
cmovel -0xd0(%rbp), %edx
addl %eax, %edx
decl %edx
cmpl -0xa4(%rbp), %edx
jae 0x51e1e
cmpb $0x72, %cl
jne 0x51a70
negl %eax
movw %ax, -0x3a(%rbp)
cwtl
xorps %xmm0, %xmm0
cvtss2sd -0xbc(%rbp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd -0xb8(%rbp), %xmm1
xorps %xmm2, %xmm2
cvtss2sd -0xb4(%rbp), %xmm2
xorps %xmm3, %xmm3
cvtss2sd -0xb0(%rbp), %xmm3
cvtss2sd -0xac(%rbp), %xmm4
movswl -0x4a(%rbp), %ecx
movl %eax, -0x150(%rbp)
movsd %xmm0, -0x148(%rbp)
movsd %xmm1, -0x140(%rbp)
movsd %xmm2, -0x138(%rbp)
movsd %xmm3, -0x130(%rbp)
movsd %xmm4, -0x128(%rbp)
movl %ecx, -0x120(%rbp)
movq -0x88(%rbp), %rsi
cmpq -0x80(%rbp), %rsi
je 0x51b21
movq -0x120(%rbp), %rax
movq %rax, 0x30(%rsi)
movups -0x150(%rbp), %xmm0
movups -0x140(%rbp), %xmm1
movups -0x130(%rbp), %xmm2
movups %xmm2, 0x20(%rsi)
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x38, %rsi
movq %rsi, -0x88(%rbp)
jmp 0x51b34
leaq -0x90(%rbp), %rdi
leaq -0x150(%rbp), %rdx
callq 0x536f2
movq -0x38(%rbp), %rax
movb (%rax), %al
cmpb $0x28, %al
jne 0x51b48
movq -0x38(%rbp), %rax
cmpb $0x28, 0x1(%rax)
je 0x51b5e
movq -0x38(%rbp), %rcx
movb 0x1(%rcx), %al
incq %rcx
movq %rcx, -0x38(%rbp)
testb %al, %al
jne 0x51b3a
xorl %eax, %eax
jmp 0x51b60
movb $0x28, %al
incl %ebx
cmpl -0xa0(%rbp), %ebx
jne 0x519aa
movq -0x88(%rbp), %rax
subq -0x90(%rbp), %rax
cmpq $0x4d0, %rax            # imm = 0x4D0
jne 0x51d2e
movq -0x160(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x52dc6
movq -0x98(%rbp), %rax
movq 0x168(%rax), %rsi
cmpq 0x170(%rax), %rsi
je 0x51d1b
movaps -0x110(%rbp), %xmm0
movaps -0x100(%rbp), %xmm1
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x20, 0x168(%rax)
jmp 0x51d2e
movq $0x0, -0x38(%rbp)
jmp 0x51d40
movl $0x12, %edx
movq 0x323ff(%rip), %rdi     # 0x83ff0
leaq 0x1b1e2(%rip), %rsi     # 0x6cdda
callq 0x9560
movl $0x1, %edx
movq 0x323e7(%rip), %rdi     # 0x83ff0
leaq 0x1b582(%rip), %rsi     # 0x6d192
callq 0x9560
movq 0x323d4(%rip), %rdi     # 0x83ff0
movl $0x22d, %esi            # imm = 0x22D
callq 0x9880
movq %rax, %r12
movl $0x3, %edx
movq %rax, %rdi
leaq 0x1981f(%rip), %rsi     # 0x6b457
callq 0x9560
movl $0x10, %edx
movq %r12, %rdi
leaq 0x1b34f(%rip), %rsi     # 0x6cf9b
callq 0x9560
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq %r12, %rdi
callq 0x9560
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x9480
movsbl %al, %esi
movq %r12, %rdi
callq 0x9070
movq %rax, %rdi
callq 0x9330
jmp 0x51d40
movl $0x7, %edx
movq 0x32354(%rip), %rdi     # 0x83ff0
leaq 0x1b2c1(%rip), %rsi     # 0x6cf64
callq 0x9560
movl $0x18, %edx
movq 0x3233c(%rip), %rdi     # 0x83ff0
leaq 0x1b2b1(%rip), %rsi     # 0x6cf6c
callq 0x9560
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq 0x32321(%rip), %rdi     # 0x83ff0
callq 0x9560
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1b29d(%rip), %rsi     # 0x6cf83
callq 0x9560
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x9480
movsbl %al, %esi
movq %r12, %rdi
callq 0x9070
movq %rax, %rdi
callq 0x9330
movl $0x1, %r15d
jmp 0x51d40
movq -0x158(%rbp), %rdi
leaq -0x110(%rbp), %rdx
callq 0x53b62
xorl %eax, %eax
movl -0x9c(%rbp), %ecx
cmpl %ecx, -0x48(%rbp)
setge %al
leal (%rax,%rax,2), %r15d
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x51d58
movq -0x80(%rbp), %rsi
subq %rdi, %rsi
callq 0x94e0
testl %r15d, %r15d
je 0x51661
jmp 0x51ed6
movl $0x12, %edx
movq 0x3227e(%rip), %rdi     # 0x83ff0
leaq 0x1b061(%rip), %rsi     # 0x6cdda
callq 0x9560
movl $0x1, %edx
movq 0x32266(%rip), %rdi     # 0x83ff0
leaq 0x1b401(%rip), %rsi     # 0x6d192
callq 0x9560
movq 0x32253(%rip), %rdi     # 0x83ff0
movl $0x244, %esi            # imm = 0x244
callq 0x9880
movq %rax, %r15
movl $0x3, %edx
movq %rax, %rdi
leaq 0x1969e(%rip), %rsi     # 0x6b457
callq 0x9560
movl $0x12, %edx
movq %r15, %rdi
leaq 0x1b206(%rip), %rsi     # 0x6cfd3
callq 0x9560
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x9200
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x9560
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x9480
movsbl %al, %esi
movq %r15, %rdi
callq 0x9070
movl $0x1, %r15d
movq %rax, %rdi
callq 0x9330
jmp 0x51d40
movl $0x12, %edx
movq 0x321c6(%rip), %rdi     # 0x83ff0
leaq 0x1afa9(%rip), %rsi     # 0x6cdda
callq 0x9560
movl $0x1, %edx
movq 0x321ae(%rip), %rdi     # 0x83ff0
leaq 0x1b349(%rip), %rsi     # 0x6d192
callq 0x9560
movq 0x3219b(%rip), %rdi     # 0x83ff0
movl $0x24d, %esi            # imm = 0x24D
callq 0x9880
movq %rax, %r15
movl $0x3, %edx
movq %rax, %rdi
leaq 0x195e6(%rip), %rsi     # 0x6b457
callq 0x9560
movl $0x12, %edx
movq %r15, %rdi
leaq 0x1b14e(%rip), %rsi     # 0x6cfd3
callq 0x9560
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x9200
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x9560
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x9480
movsbl %al, %esi
movq %r15, %rdi
callq 0x9070
movl $0x1, %r15d
movq %rax, %rdi
callq 0x9330
jmp 0x51d40
cmpl $0x3, %r15d
jne 0x51ef6
movq -0x98(%rbp), %rcx
movq 0x120(%rcx), %rax
cmpq 0x128(%rcx), %rax
setne %bl
jmp 0x51ef8
xorl %ebx, %ebx
leaq -0x378(%rbp), %rdi
callq 0x9170
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x51f1d
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x94e0
movl %ebx, %eax
addq $0x358, %rsp            # imm = 0x358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x51f96
jmp 0x51f6f
jmp 0x51f6f
jmp 0x51f6f
jmp 0x51f6f
jmp 0x51f6f
jmp 0x51f6f
jmp 0x51f6f
movq %rax, %rbx
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x51f72
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x94e0
jmp 0x51f72
jmp 0x51f6f
jmp 0x51f6f
movq %rax, %rbx
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x51f8a
movq -0x80(%rbp), %rsi
subq %rdi, %rsi
callq 0x94e0
leaq -0x378(%rbp), %rdi
callq 0x9170
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x51faf
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x94e0
movq %rbx, %rdi
callq 0x98b0
nop