// File: kobanium[P]Ray/src/mcts/UctSearch.cpp
// Function: InitializeUctSearch()
void
InitializeUctSearch( void )
{
  int i;

  // Progressive Wideningの初期化  
  pw[0] = 0;
  for (i = 1; i <= PURE_BOARD_MAX; i++) {  
    pw[i] = pw[i - 1] + static_cast<int>(40 * pow(PROGRESSIVE_WIDENING, i - 1));
    if (pw[i] > 10000000) break;
  }
  for (i = i + 1; i <= PURE_BOARD_MAX; i++) { 
    pw[i] = INT_MAX;
  }

  mutex_nodes = new std::mutex[uct_hash_size];

  // UCTのノードのメモリを確保
  uct_node = new uct_node_t[uct_hash_size];

  std::cerr << "Require " << uct_hash_size * sizeof(uct_node_t) / 1024 / 1024 << " Mbytes for Uct Node" << std::endl << std::endl;
  std::cerr << sizeof(uct_node_t) << std::endl;
  std::cerr << sizeof(child_node_t) * UCT_CHILD_MAX << std::endl;
  
  if (uct_node == NULL) {
    std::cerr << "Cannot allocate memory !!" << std::endl;
    std::cerr << "You must reduce tree size !!" << std::endl;
    exit(1);
  }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, 0x1aaeadbe(%rip)  # 0x1ab73cd0
movl $0x1, -0x4(%rbp)
cmpl $0x169, -0x4(%rbp)      # imm = 0x169
jg 0x88f98
movl -0x4(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x1aaead9e(%rip), %rax  # 0x1ab73cd0
movl (%rax,%rcx,4), %eax
movl %eax, -0x8(%rbp)
movl -0x4(%rbp), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm1
movsd 0x26216(%rip), %xmm0    # 0xaf160
callq 0x7990
movl -0x8(%rbp), %edx
movaps %xmm0, %xmm1
movsd 0x261fb(%rip), %xmm0    # 0xaf158
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
addl %eax, %edx
movslq -0x4(%rbp), %rcx
leaq 0x1aaead5e(%rip), %rax  # 0x1ab73cd0
movl %edx, (%rax,%rcx,4)
movslq -0x4(%rbp), %rcx
leaq 0x1aaead50(%rip), %rax  # 0x1ab73cd0
cmpl $0x989680, (%rax,%rcx,4) # imm = 0x989680
jle 0x88f8b
jmp 0x88f98
jmp 0x88f8d
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x88f19
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
cmpl $0x169, -0x4(%rbp)      # imm = 0x169
jg 0x88fc7
movslq -0x4(%rbp), %rcx
leaq 0x1aaead1b(%rip), %rax  # 0x1ab73cd0
movl $0x7fffffff, (%rax,%rcx,4) # imm = 0x7FFFFFFF
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x88fa1
leaq 0x5ea92(%rip), %rax     # 0xe7a60
movl (%rax), %eax
movq %rax, -0x18(%rbp)
movl $0x28, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x7040
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, -0x10(%rbp)
cmpq $0x0, %rax
je 0x89042
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
imulq $0x28, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x28(%rbp)
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq %rdi, -0x30(%rbp)
callq 0x635b0
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
addq $0x28, %rax
cmpq %rcx, %rax
movq %rax, -0x20(%rbp)
jne 0x89020
movq -0x10(%rbp), %rax
movq %rax, 0x1aaeb22b(%rip)  # 0x1ab74278
leaq 0x5ea0c(%rip), %rax     # 0xe7a60
movl (%rax), %eax
movl $0x4548, %ecx           # imm = 0x4548
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x7040
movq %rax, 0x1aac3a32(%rip)  # 0x1ab4cab0
movq 0x5df6b(%rip), %rdi     # 0xe6ff0
leaq 0x26100(%rip), %rsi     # 0xaf18c
callq 0x7530
movq %rax, %rdi
leaq 0x5e9c5(%rip), %rax     # 0xe7a60
movl (%rax), %eax
imulq $0x4548, %rax, %rsi     # imm = 0x4548
shrq $0xa, %rsi
shrq $0xa, %rsi
callq 0x7100
movq %rax, %rdi
leaq 0x260da(%rip), %rsi     # 0xaf195
callq 0x7530
movq %rax, %rdi
movq 0x5de9e(%rip), %rsi     # 0xe6f68
callq 0x75b0
movq %rax, %rdi
movq 0x5de8f(%rip), %rsi     # 0xe6f68
callq 0x75b0
movq 0x5df0b(%rip), %rdi     # 0xe6ff0
movl $0x4548, %esi           # imm = 0x4548
callq 0x7100
movq %rax, %rdi
movq 0x5de6f(%rip), %rsi     # 0xe6f68
callq 0x75b0
movq 0x5deeb(%rip), %rdi     # 0xe6ff0
movl $0x2798, %esi           # imm = 0x2798
callq 0x7100
movq %rax, %rdi
movq 0x5de4f(%rip), %rsi     # 0xe6f68
callq 0x75b0
cmpq $0x0, 0x1aac398a(%rip)  # 0x1ab4cab0
jne 0x89176
movq 0x5dec1(%rip), %rdi     # 0xe6ff0
leaq 0x26074(%rip), %rsi     # 0xaf1aa
callq 0x7530
movq %rax, %rdi
movq 0x5de23(%rip), %rsi     # 0xe6f68
callq 0x75b0
movq 0x5de9f(%rip), %rdi     # 0xe6ff0
leaq 0x2606c(%rip), %rsi     # 0xaf1c4
callq 0x7530
movq %rax, %rdi
movq 0x5de01(%rip), %rsi     # 0xe6f68
callq 0x75b0
movl $0x1, %edi
callq 0x76a0
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)