// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x24(%rbp)
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x2c(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x30(%rbp)
testb $0x1, 0xc5be9(%rip)     # 0xe7580
jne 0x2199e
jmp 0x21e95
callq 0x9bce0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x9c660
movq 0xc5635(%rip), %rdi     # 0xe6ff0
leaq 0x8a74e(%rip), %rsi     # 0xac110
callq 0x7530
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x4548, %rcx, %rcx     # imm = 0x4548
addq %rcx, %rax
addq $0x1c, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x4548, %rcx, %rcx     # imm = 0x4548
addq %rcx, %rax
movl 0x18(%rax), %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x21a53
movq -0x40(%rbp), %rdi
movslq -0x44(%rbp), %rax
imulq $0x1c, %rax, %rax
addq %rax, %rdi
addq $0x4, %rdi
callq 0x25780
cmpl -0x2c(%rbp), %eax
jle 0x21a46
movq -0x40(%rbp), %rdi
movslq -0x44(%rbp), %rax
imulq $0x1c, %rax, %rax
addq %rax, %rdi
addq $0x4, %rdi
callq 0x25780
movl %eax, -0x2c(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x21a48
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x21a00
movq -0x40(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movswl (%rax), %eax
cmpl $0x0, %eax
jne 0x21a7f
movq 0xc557f(%rip), %rdi     # 0xe6ff0
leaq 0x8a6a9(%rip), %rsi     # 0xac121
callq 0x7530
jmp 0x21af5
movq -0x40(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movswl (%rax), %eax
leaq 0xc5fb4(%rip), %rcx     # 0xe7a4c
cltd
idivl (%rcx)
movl %edx, %eax
subl $0x5, %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0xc5543(%rip), %rdi     # 0xe6ff0
leaq 0x8a8ec(%rip), %rax     # 0xac3a0
movsbl (%rax,%rcx), %esi
callq 0x7660
movq %rax, %rdi
leaq 0xc5f7d(%rip), %rax     # 0xe7a44
movl (%rax), %esi
addl $0x1, %esi
movq -0x40(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movswl (%rax), %eax
leaq 0xc5f67(%rip), %rcx     # 0xe7a4c
cltd
idivl (%rcx)
subl $0x5, %eax
addl $0x1, %eax
subl %eax, %esi
callq 0x7980
leaq 0x1c78570c(%rip), %rax  # 0x1c7a7208
movq (%rax), %rax
movslq -0x24(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x8(%rax)
jne 0x21b25
movq 0xc54d9(%rip), %rdi     # 0xe6ff0
leaq 0x8a608(%rip), %rsi     # 0xac126
callq 0x7530
jmp 0x21b55
leaq 0x1c7856dc(%rip), %rax  # 0x1c7a7208
movq (%rax), %rax
movslq -0x24(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpl $0x2, 0x8(%rax)
jne 0x21b53
movq 0xc54a9(%rip), %rdi     # 0xe6ff0
leaq 0x8a5e2(%rip), %rsi     # 0xac130
callq 0x7530
jmp 0x21b55
movq -0x20(%rbp), %rdi
movq -0x40(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movswl (%rax), %esi
movl -0x30(%rbp), %edx
callq 0x9dbc0
movl -0x30(%rbp), %edi
callq 0x25810
movl %eax, -0x30(%rbp)
movq -0x40(%rbp), %rdi
movslq -0x28(%rbp), %rax
imulq $0x1c, %rax, %rax
addq %rax, %rdi
addq $0xc, %rdi
callq 0x25780
movl %eax, %esi
movq 0xc5451(%rip), %rdi     # 0xe6ff0
callq 0x7980
movq %rax, %rdi
leaq 0x8a49a(%rip), %rsi     # 0xac048
callq 0x7530
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rdi
movslq -0x28(%rbp), %rax
imulq $0x1c, %rax, %rax
addq %rax, %rdi
addq $0x4, %rdi
callq 0x25780
movq -0x50(%rbp), %rdi
movl %eax, %esi
callq 0x7980
movq %rax, %rdi
leaq 0x8bdc2(%rip), %rsi     # 0xad9a6
callq 0x7530
movq -0x40(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, -0x24(%rbp)
cmpl $-0x1, -0x24(%rbp)
je 0x21e70
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x4548, %rcx, %rcx     # imm = 0x4548
addq %rcx, %rax
addq $0x1c, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x4548, %rcx, %rcx     # imm = 0x4548
addq %rcx, %rax
movl 0x18(%rax), %eax
movl %eax, -0x34(%rbp)
movl $0x32, -0x2c(%rbp)
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x21ca2
movq -0x40(%rbp), %rdi
movslq -0x48(%rbp), %rax
imulq $0x1c, %rax, %rax
addq %rax, %rdi
addq $0x4, %rdi
callq 0x25780
cmpl -0x2c(%rbp), %eax
jle 0x21c95
movq -0x40(%rbp), %rdi
movslq -0x48(%rbp), %rax
imulq $0x1c, %rax, %rax
addq %rax, %rdi
addq $0x4, %rdi
callq 0x25780
movl %eax, -0x2c(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x21c97
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x21c4f
cmpl $-0x1, -0x28(%rbp)
jne 0x21cad
jmp 0x21e70
movq 0xc533c(%rip), %rdi     # 0xe6ff0
leaq 0x8a47f(%rip), %rsi     # 0xac13a
callq 0x7530
movq -0x40(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movswl (%rax), %eax
cmpl $0x0, %eax
jne 0x21cec
movq 0xc5312(%rip), %rdi     # 0xe6ff0
leaq 0x8a43c(%rip), %rsi     # 0xac121
callq 0x7530
jmp 0x21d62
movq -0x40(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movswl (%rax), %eax
leaq 0xc5d47(%rip), %rcx     # 0xe7a4c
cltd
idivl (%rcx)
movl %edx, %eax
subl $0x5, %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0xc52d6(%rip), %rdi     # 0xe6ff0
leaq 0x8a67f(%rip), %rax     # 0xac3a0
movsbl (%rax,%rcx), %esi
callq 0x7660
movq %rax, %rdi
leaq 0xc5d10(%rip), %rax     # 0xe7a44
movl (%rax), %esi
addl $0x1, %esi
movq -0x40(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movswl (%rax), %eax
leaq 0xc5cfa(%rip), %rcx     # 0xe7a4c
cltd
idivl (%rcx)
subl $0x5, %eax
addl $0x1, %eax
subl %eax, %esi
callq 0x7980
leaq 0x1c78549f(%rip), %rax  # 0x1c7a7208
movq (%rax), %rax
movslq -0x24(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x8(%rax)
jne 0x21d92
movq 0xc526c(%rip), %rdi     # 0xe6ff0
leaq 0x8a39b(%rip), %rsi     # 0xac126
callq 0x7530
jmp 0x21dc2
leaq 0x1c78546f(%rip), %rax  # 0x1c7a7208
movq (%rax), %rax
movslq -0x24(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpl $0x2, 0x8(%rax)
jne 0x21dc0
movq 0xc523c(%rip), %rdi     # 0xe6ff0
leaq 0x8a375(%rip), %rsi     # 0xac130
callq 0x7530
jmp 0x21dc2
movq -0x20(%rbp), %rdi
movq -0x40(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movswl (%rax), %esi
movl -0x30(%rbp), %edx
callq 0x9dbc0
movl -0x30(%rbp), %edi
callq 0x25810
movl %eax, -0x30(%rbp)
movq -0x40(%rbp), %rdi
movslq -0x28(%rbp), %rax
imulq $0x1c, %rax, %rax
addq %rax, %rdi
addq $0xc, %rdi
callq 0x25780
movl %eax, %esi
movq 0xc51e4(%rip), %rdi     # 0xe6ff0
callq 0x7980
movq %rax, %rdi
leaq 0x8a22d(%rip), %rsi     # 0xac048
callq 0x7530
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rdi
movslq -0x28(%rbp), %rax
imulq $0x1c, %rax, %rax
addq %rax, %rdi
addq $0x4, %rdi
callq 0x25780
movq -0x58(%rbp), %rdi
movl %eax, %esi
callq 0x7980
movq %rax, %rdi
leaq 0x8bb55(%rip), %rsi     # 0xad9a6
callq 0x7530
movq -0x40(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, -0x24(%rbp)
jmp 0x21bfe
movq 0xc5179(%rip), %rdi     # 0xe6ff0
movq 0xc50ea(%rip), %rsi     # 0xe6f68
callq 0x75b0
movq -0x20(%rbp), %rdi
callq 0x20430
movq -0x20(%rbp), %rdi
callq 0x9bd30
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)