// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
subq $0xc8, %rsp
cmpb $0x0, 0x12(%rsi)
movq %rsi, %rbx
js 0x14b64
addq $0x18, %rbx
jmp 0x14d00
movq 0x20(%rbx), %r8
xorl %esi, %esi
movl $0x0, %eax
leaq 0x10(%r8), %rdi
cmpq $0x2, %r8
cmovaeq %rdi, %rax
jb 0x14b8c
movzwl 0x6(%r8), %esi
imulq $0x28, %rsi, %rsi
addq %rsi, %rdi
movq %rdi, %rsi
vmovsd 0xaa24(%rip), %xmm0     # 0x1f5b8
vmovsd 0xaa34(%rip), %xmm1     # 0x1f5d0
vmovsd 0xaa24(%rip), %xmm2     # 0x1f5c8
vmovsd 0xaa14(%rip), %xmm3     # 0x1f5c0
xorl %ebx, %ebx
cmpq %rsi, %rax
je 0x14c01
movsbl 0x12(%rax), %edi
testl %edi, %edi
js 0x14bcc
cmpl %edx, %edi
jne 0x14bd9
vcvtusi2sdq 0x8(%rax), %xmm5, %xmm4
vsubsd %xmm4, %xmm1, %xmm4
jmp 0x14bef
movq (%rax), %rdi
shrq %rdi
vcvtsi2sd %rdi, %xmm5, %xmm4
jmp 0x14bef
vcvtusi2sdq 0x8(%rax), %xmm5, %xmm4
testb %dil, %dil
je 0x14beb
vaddsd %xmm3, %xmm4, %xmm4
jmp 0x14bef
vaddsd %xmm2, %xmm4, %xmm4
vucomisd %xmm0, %xmm4
vmaxsd %xmm0, %xmm4, %xmm0
cmovaq %rax, %rbx
addq $0x28, %rax
jmp 0x14bae
testq %rbx, %rbx
je 0x14d0d
testl %ecx, %ecx
je 0x14cfc
vcvtusi2ssq (%rbx), %xmm5, %xmm0
leaq 0x88(%rsp), %r14
vmulss 0xa97c(%rip), %xmm0, %xmm0 # 0x1f5a4
vcvtusi2ssq 0x8(%rbx), %xmm5, %xmm1
vdivss %xmm1, %xmm0, %xmm0
vcvtss2sd %xmm0, %xmm0, %xmm0
vmulsd 0x8669(%rip), %xmm0, %xmm0 # 0x1d2a8
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0xf350
leaq 0xad52(%rip), %rsi      # 0x1f9a3
leaq 0x28(%rsp), %rdi
movq %r14, %rdx
callq 0x8423
leaq 0xad4c(%rip), %rdx      # 0x1f9b1
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x6821
movq 0x8(%rbx), %rsi
leaq 0x8(%rsp), %rdi
callq 0xaf8f
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x8365
leaq 0x7e1b(%rip), %rdx      # 0x1cab8
leaq 0xa8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x6821
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
callq 0xac65
movq %r14, %rdi
callq 0x4130
leaq 0x68(%rsp), %rdi
callq 0x4130
leaq 0x8(%rsp), %rdi
callq 0x4130
leaq 0x48(%rsp), %rdi
callq 0x4130
leaq 0x28(%rsp), %rdi
callq 0x4130
leaq 0x88(%rsp), %rdi
callq 0x4130
addq $0x14, %rbx
movl (%rbx), %eax
addq $0xc8, %rsp
popq %rbx
popq %r14
retq
leaq 0xac51(%rip), %rdi      # 0x1f965
leaq 0xa9b7(%rip), %rsi      # 0x1f6d2
leaq 0xac47(%rip), %rcx      # 0x1f969
movl $0x17f, %edx            # imm = 0x17F
callq 0x41c0
leaq 0x68(%rsp), %rdi
movq %rax, %rbx
callq 0x4130
jmp 0x14d3e
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x4130
jmp 0x14d4d
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x4130
jmp 0x14d5c
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x4130
jmp 0x14d6b
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x4130
movq %rbx, %rdi
callq 0x4590