// File: /workspace/github_cpp_makefile_star2_O2/kobanium[P]Ray/src/common/Message.cpp
// Function: PrintBestSequence(game_info_t const*, uct_node_t const*, int, int)
void
PrintBestSequence( const game_info_t *game, const uct_node_t *uct_node, const int root, const int start_color )
{
  game_info_t *search_result;
  int current = root;
  int index = -1;
  int max = 0;
  int color = start_color;
  int child_num;
  const child_node_t *uct_child;

  if (!debug_message) return ;

  search_result = AllocateGame();
  CopyGame(search_result, game);

  std::cerr << "Best Sequence : ";

  uct_child = uct_node[current].child;
  child_num = uct_node[current].child_num;

  for (int i = 0; i < child_num; i++) {
    if (uct_child[i].move_count > max) {
      max = uct_child[i].move_count;
      index = i;
    }
  }

  if (uct_child[index].pos == PASS) std::cerr << "PASS";
  else std::cerr << GOGUI_X(uct_child[index].pos) << GOGUI_Y(uct_child[index].pos);
  if (node_hash[current].color == S_BLACK) std::cerr << "(BLACK : ";
  else if (node_hash[current].color == S_WHITE) std::cerr << "(WHITE : ";


  PutStone(search_result, uct_child[index].pos, color);
  color = GetOppositeColor(color);

  std::cerr << uct_child[index].win << "/" << uct_child[index].move_count << ")";

  current = uct_child[index].index;
  
  while (current != NOT_EXPANDED) {
    uct_child = uct_node[current].child;
    child_num = uct_node[current].child_num;

    max = 50;
    index = -1;

    for (int i = 0; i < child_num; i++) {
      if (uct_child[i].move_count > max) {
        max = uct_child[i].move_count;
        index = i;
      }
    }

    if (index == -1) break;

    std::cerr << "->";

    if (uct_child[index].pos == PASS) std::cerr << "PASS";
    else std::cerr << GOGUI_X(uct_child[index].pos) << GOGUI_Y(uct_child[index].pos);

    if (node_hash[current].color == S_BLACK) std::cerr << "(BLACK : ";
    else if (node_hash[current].color == S_WHITE) std::cerr << "(WHITE : ";

    PutStone(search_result, uct_child[index].pos, color);

    color = GetOppositeColor(color);

    std::cerr << uct_child[index].win << "/" << uct_child[index].move_count << ")";

    current = uct_child[index].index;

  }

  std::cerr << std::endl;

  PrintBoard(search_result);
  FreeGame(search_result);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpb $0x1, 0x51342(%rip)     # 0x61430
jne 0x10166
movl %ecx, %ebx
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %r12
callq 0x3b148
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq %r12, %rsi
callq 0x3b5f2
movq 0x50eda(%rip), %rdi     # 0x60ff0
leaq 0x33ff3(%rip), %rsi     # 0x44110
callq 0x63c0
movslq %ebp, %r14
imulq $0x4548, %r14, %rsi     # imm = 0x4548
leaq (%r15,%rsi), %rax
addq $0x1c, %rax
movl -0x4(%rax), %ecx
xorl %edx, %edx
testl %ecx, %ecx
cmovlel %edx, %ecx
addq %r15, %rsi
addq $0x20, %rsi
pushq $-0x1
popq %rdi
xorl %r8d, %r8d
cmpq %rdx, %rcx
je 0x10175
movl (%rsi), %r9d
cmpl %r8d, %r9d
jle 0x1015d
movl (%rsi), %r8d
movl %edx, %edi
incq %rdx
addq $0x1c, %rsi
jmp 0x1014b
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, 0x10(%rsp)
movslq %edi, %rcx
imulq $0x1c, %rcx, %rcx
leaq (%rax,%rcx), %r13
movswl (%rax,%rcx), %eax
testl %eax, %eax
je 0x101d7
leaq 0x51728(%rip), %r15     # 0x618bc
cltd
idivl (%r15)
movslq %edx, %rax
leaq 0x341fe(%rip), %rcx     # 0x443a0
movsbl -0x4(%rax,%rcx), %esi
movq 0x50e42(%rip), %rdi     # 0x60ff0
callq 0x6480
movq %rax, %rdi
leaq 0x516f7(%rip), %rax     # 0x618b4
movl (%rax), %ecx
movswl (%r13), %eax
cltd
idivl (%r15)
negl %eax
leal (%rcx,%rax), %esi
addl $0x5, %esi
callq 0x6700
jmp 0x101ea
movq 0x50e12(%rip), %rdi     # 0x60ff0
leaq 0x33f3c(%rip), %rsi     # 0x44121
callq 0x63c0
leaq 0x1c710e97(%rip), %rax  # 0x1c721088
movq (%rax), %rax
imulq $0x18, %r14, %rcx
movl 0x8(%rax,%rcx), %eax
cmpl $0x1, %eax
je 0x10372
cmpl $0x2, %eax
jne 0x1021d
leaq 0x33f1f(%rip), %rsi     # 0x44130
movq 0x50dd8(%rip), %rdi     # 0x60ff0
callq 0x63c0
movq 0x10(%rsp), %rax
leaq 0x20(%rax), %rbp
movq 0x50dc3(%rip), %r12     # 0x60ff0
movswl (%r13), %esi
movq 0x8(%rsp), %rdi
movl %ebx, %edx
callq 0x3c2f8
movl 0xc(%r13), %esi
movq %r12, %rdi
callq 0x6700
movq %rax, %rdi
leaq 0x33df4(%rip), %rsi     # 0x44048
callq 0x63c0
movl 0x4(%r13), %esi
movq %rax, %rdi
callq 0x6700
movq %rax, %rdi
leaq 0x356b1(%rip), %rsi     # 0x45920
callq 0x63c0
movslq 0x10(%r13), %r14
cmpq $-0x1, %r14
je 0x1037e
xorl $0x3, %ebx
imulq $0x4548, %r14, %rax     # imm = 0x4548
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax), %r15
addq $0x1c, %r15
movl -0x4(%r15), %ecx
testl %ecx, %ecx
movl $0x0, %edx
cmovlel %edx, %ecx
addq %rbp, %rax
xorl %edx, %edx
pushq $-0x1
popq %r13
pushq $0x32
popq %rsi
cmpq %rdx, %rcx
je 0x102cc
movl (%rax), %edi
cmpl %esi, %edi
jle 0x102c3
movl (%rax), %esi
movl %edx, %r13d
incq %rdx
addq $0x1c, %rax
jmp 0x102b3
cmpl $-0x1, %r13d
je 0x1037e
movq %r12, %rdi
leaq 0x33e5a(%rip), %rsi     # 0x4413a
callq 0x63c0
movslq %r13d, %rax
imulq $0x1c, %rax, %rax
leaq (%r15,%rax), %r13
movswl (%r15,%rax), %eax
testl %eax, %eax
je 0x1033f
cltd
leaq 0x515bb(%rip), %r15     # 0x618bc
idivl (%r15)
movslq %edx, %rax
leaq 0x34092(%rip), %rcx     # 0x443a0
movsbl -0x4(%rax,%rcx), %esi
movq %r12, %rdi
callq 0x6480
movq %rax, %rdi
leaq 0x5158f(%rip), %rax     # 0x618b4
movl (%rax), %ecx
movswl (%r13), %eax
cltd
idivl (%r15)
negl %eax
leal (%rcx,%rax), %esi
addl $0x5, %esi
callq 0x6700
jmp 0x1034e
movq %r12, %rdi
leaq 0x33dd8(%rip), %rsi     # 0x44121
callq 0x63c0
leaq 0x1c710d33(%rip), %rax  # 0x1c721088
movq (%rax), %rax
imulq $0x18, %r14, %rcx
movl 0x8(%rax,%rcx), %eax
cmpl $0x2, %eax
je 0x1020a
cmpl $0x1, %eax
jne 0x1022d
leaq 0x33dad(%rip), %rsi     # 0x44126
jmp 0x10211
movq 0x50c6b(%rip), %rdi     # 0x60ff0
callq 0x6190
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0xf344
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3b163