// File: /workspace/github_cpp_makefile_star2_O3/tewalds[P]pentagod/agentmcts.cpp
// Function: AgentMCTS::return_move(AgentMCTS::Node const*, int, int) const
Move AgentMCTS::return_move(const Node * node, int toplay, int verbose) const {
	if(node->outcome >= 0)
		return node->bestmove;

	double val, maxval = -1000000000000.0; //1 trillion

	Node * ret = NULL,
		 * child = node->children.begin(),
		 * end = node->children.end();

	for( ; child != end; child++){
		if(child->outcome >= 0){
			if(child->outcome == toplay) val =  800000000000.0 - child->exp.num(); //shortest win
			else if(child->outcome == 0) val = -400000000000.0 + child->exp.num(); //longest tie
			else                         val = -800000000000.0 + child->exp.num(); //longest loss
		}else{ //not proven
//			val = child->exp.num(); //num simulations
			val = child->exp.sum(); //num wins
		}

		if(maxval < val){
			maxval = val;
			ret = child;
		}
	}

	assert(ret);

	if(verbose)
		logerr("Score:       " + to_str(ret->exp.avg()*100., 2) + "% / " + to_str(ret->exp.num()) + "\n");

	return ret->move;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xc8, %rsp
cmpb $0x0, 0x12(%rsi)
movq %rsi, %rbx
js 0x1d7d6
addq $0x18, %rbx
jmp 0x1d889
movq 0x20(%rbx), %r8
xorl %esi, %esi
movl $0x0, %eax
leaq 0x10(%r8), %rdi
cmpq $0x2, %r8
cmovaeq %rdi, %rax
jb 0x1d7fc
movzwl 0x6(%r8), %esi
leaq (%rsi,%rsi,4), %rsi
leaq (%rdi,%rsi,8), %rsi
cmpq %rsi, %rax
je 0x1db31
vmovsd 0xde23(%rip), %xmm0     # 0x2b630
vmovsd 0xde33(%rip), %xmm1     # 0x2b648
vmovsd 0xde23(%rip), %xmm2     # 0x2b640
vmovsd 0xde13(%rip), %xmm3     # 0x2b638
xorl %ebx, %ebx
movsbl 0x12(%rax), %edi
testl %edi, %edi
js 0x1d840
cmpl %edx, %edi
jne 0x1d84d
vcvtusi2sdq 0x8(%rax), %xmm5, %xmm4
vsubsd %xmm4, %xmm1, %xmm4
jmp 0x1d863
movq (%rax), %rdi
shrq %rdi
vcvtsi2sd %rdi, %xmm5, %xmm4
jmp 0x1d863
vcvtusi2sdq 0x8(%rax), %xmm5, %xmm4
testb %dil, %dil
je 0x1d85f
vaddsd %xmm3, %xmm4, %xmm4
jmp 0x1d863
vaddsd %xmm2, %xmm4, %xmm4
vucomisd %xmm0, %xmm4
vmaxsd %xmm0, %xmm4, %xmm0
cmovaq %rax, %rbx
addq $0x28, %rax
cmpq %rsi, %rax
jne 0x1d827
testq %rbx, %rbx
je 0x1db31
testl %ecx, %ecx
jne 0x1d89a
addq $0x14, %rbx
movl (%rbx), %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
vcvtusi2ssq (%rbx), %xmm5, %xmm0
leaq 0xa8(%rsp), %r14
movl $0x2, %esi
movq %r14, %rdi
vmulss 0xdda0(%rip), %xmm0, %xmm0 # 0x2b658
vcvtusi2ssq 0x8(%rbx), %xmm5, %xmm1
vdivss %xmm1, %xmm0, %xmm0
vcvtss2sd %xmm0, %xmm0, %xmm0
vmulsd 0xba09(%rip), %xmm0, %xmm0 # 0x292d8
callq 0x15694
leaq 0xe164(%rip), %rcx      # 0x2ba3f
movl $0xd, %r8d
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4330
leaq 0x78(%rsp), %r14
movq %rax, %rcx
addq $0x10, %rcx
movq %r14, -0x10(%r14)
movq (%rax), %rdx
cmpq %rcx, %rdx
jne 0x1d910
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%r14)
jmp 0x1d91d
movq %rdx, 0x68(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x78(%rsp)
movq 0x8(%rax), %rdx
leaq 0x68(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0xe10d(%rip), %rsi      # 0x2ba4d
callq 0x4610
leaq 0x38(%rsp), %r15
movq %rax, %rcx
addq $0x10, %rcx
movq %r15, -0x10(%r15)
movq (%rax), %rdx
cmpq %rcx, %rdx
jne 0x1d968
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%r15)
jmp 0x1d975
movq %rdx, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
movq 0x8(%rax), %rdx
movq %rdx, 0x30(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x8(%rbx), %rsi
leaq 0x48(%rsp), %rdi
callq 0xd5e9
movq 0x30(%rsp), %r8
movq 0x50(%rsp), %rdx
movq 0x28(%rsp), %rcx
movl $0xf, %edi
leaq (%rdx,%r8), %rax
cmpq %r15, %rcx
je 0x1d9bd
movq 0x38(%rsp), %rdi
movq 0x48(%rsp), %rsi
cmpq %rdi, %rax
jbe 0x1d9e0
leaq 0x58(%rsp), %r9
movl $0xf, %edi
cmpq %r9, %rsi
je 0x1d9db
movq 0x58(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x1d9ec
leaq 0x28(%rsp), %rdi
callq 0x40b0
jmp 0x1d9fa
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4330
leaq 0x18(%rsp), %rdx
leaq 0x10(%rax), %rcx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
cmpq %rcx, %rsi
jne 0x1da19
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%rdx)
jmp 0x1da26
movq %rsi, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
movq 0x8(%rax), %rsi
movq %rax, %rdx
addq $0x8, %rdx
movq %rsi, 0x10(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0xb098(%rip), %rsi      # 0x28ae2
leaq 0x8(%rsp), %rdi
callq 0x4610
leaq 0x98(%rsp), %r12
movq %rax, %rcx
addq $0x10, %rcx
movq %r12, -0x10(%r12)
movq (%rax), %rdi
cmpq %rcx, %rdi
jne 0x1da7f
vmovupd (%rcx), %xmm0
movq %r12, %rdi
vmovupd %xmm0, (%r12)
jmp 0x1da92
movq %rdi, 0x88(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x98(%rsp)
movq 0x8(%rax), %rdx
movq %rdx, 0x90(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x1852c(%rip), %rax     # 0x35fe0
movq (%rax), %rsi
callq 0x4320
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x1dace
callq 0x42b0
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1dae1
callq 0x42b0
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1daf4
callq 0x42b0
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x1db03
callq 0x42b0
movq 0x68(%rsp), %rdi
cmpq %r14, %rdi
je 0x1db12
callq 0x42b0
leaq 0xb8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1d885
callq 0x42b0
jmp 0x1d885
leaq 0xdec9(%rip), %rdi      # 0x2ba01
leaq 0xdc2f(%rip), %rsi      # 0x2b76e
leaq 0xdebf(%rip), %rcx      # 0x2ba05
movl $0x17f, %edx            # imm = 0x17F
callq 0x41b0
leaq 0x18(%rsp), %rcx
movq %rax, %rbx
movq -0x10(%rcx), %rdi
cmpq %rcx, %rdi
je 0x1db6b
callq 0x42b0
jmp 0x1db6b
movq %rax, %rbx
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1db83
callq 0x42b0
jmp 0x1db83
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x1db97
callq 0x42b0
jmp 0x1db97
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %r14, %rdi
je 0x1dbab
callq 0x42b0
jmp 0x1dbab
movq %rax, %rbx
leaq 0xb8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1dbc1
callq 0x42b0
movq %rbx, %rdi
callq 0x45b0
nop