// File: tewalds[P]pentagod/agentpns.cpp
// Function: AgentPNS::return_move(AgentPNS::Node const*, int, int) const
Move AgentPNS::return_move(const Node * node, int toplay, int verbose) const {
	double val, maxval = -1000000000000.0; //1 trillion

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

	for( ; child != end; child++){
		int outcome = child->to_outcome(toplay);
		if(outcome >= 0){
			if(outcome == toplay) val =  800000000000.0 - (double)child->work; //shortest win
			else if(outcome == 0) val = -400000000000.0 + (double)child->work; //longest tie
			else                  val = -800000000000.0 + (double)child->work; //longest loss
		}else{ //not proven
			val = child->work;
		}

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

	assert(ret);

	if(verbose)
		logerr(ret->to_s() + "\n");

	return ret->move;
}

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0x98(%rsp)
movq %rsi, 0x90(%rsp)
movl %edx, 0x8c(%rsp)
movl %ecx, 0x88(%rsp)
vmovsd 0xb0ab(%rip), %xmm0     # 0x405a8
vmovsd %xmm0, 0x78(%rsp)
movq $0x0, 0x70(%rsp)
movq 0x90(%rsp), %rdi
addq $0x18, %rdi
callq 0x369f0
movq %rax, 0x68(%rsp)
movq 0x90(%rsp), %rdi
addq $0x18, %rdi
callq 0x36a40
movq %rax, 0x60(%rsp)
movq 0x68(%rsp), %rax
cmpq 0x60(%rsp), %rax
je 0x3563b
movq 0x68(%rsp), %rdi
movl 0x8c(%rsp), %esi
callq 0x36f90
movl %eax, 0x5c(%rsp)
cmpl $0x0, 0x5c(%rsp)
jl 0x355e3
movl 0x5c(%rsp), %eax
cmpl 0x8c(%rsp), %eax
jne 0x35594
movq 0x68(%rsp), %rax
vcvtusi2sdq 0x8(%rax), %xmm0, %xmm1
vmovsd 0xb03b(%rip), %xmm0     # 0x405c0
vsubsd %xmm1, %xmm0, %xmm0
vmovsd %xmm0, 0x80(%rsp)
jmp 0x355e1
cmpl $0x0, 0x5c(%rsp)
jne 0x355be
movq 0x68(%rsp), %rax
vcvtusi2sdq 0x8(%rax), %xmm0, %xmm1
vmovsd 0xb009(%rip), %xmm0     # 0x405b8
vaddsd %xmm1, %xmm0, %xmm0
vmovsd %xmm0, 0x80(%rsp)
jmp 0x355df
movq 0x68(%rsp), %rax
vcvtusi2sdq 0x8(%rax), %xmm0, %xmm1
vmovsd 0xafde(%rip), %xmm0     # 0x405b0
vaddsd %xmm1, %xmm0, %xmm0
vmovsd %xmm0, 0x80(%rsp)
jmp 0x355e1
jmp 0x355f8
movq 0x68(%rsp), %rax
vcvtusi2sdq 0x8(%rax), %xmm0, %xmm0
vmovsd %xmm0, 0x80(%rsp)
vmovsd 0x78(%rsp), %xmm1
vmovsd 0x80(%rsp), %xmm0
vucomisd %xmm1, %xmm0
jbe 0x35626
vmovsd 0x80(%rsp), %xmm0
vmovsd %xmm0, 0x78(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x70(%rsp)
jmp 0x35628
movq 0x68(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x68(%rsp)
jmp 0x35538
cmpq $0x0, 0x70(%rsp)
je 0x35645
jmp 0x35664
leaq 0xb319(%rip), %rdi      # 0x40965
leaq 0xbd19(%rip), %rsi      # 0x4136c
movl $0x142, %edx            # imm = 0x142
leaq 0xbe18(%rip), %rcx      # 0x41477
callq 0x4250
cmpl $0x0, 0x88(%rsp)
je 0x356f2
movq 0x70(%rsp), %rsi
leaq 0x18(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x36b50
movq (%rsp), %rsi
leaq 0x8420(%rip), %rdx      # 0x3dab0
leaq 0x38(%rsp), %rdi
callq 0x93b0
jmp 0x3569c
leaq 0x38(%rsp), %rdi
callq 0x15ad0
jmp 0x356a8
leaq 0x38(%rsp), %rdi
callq 0x4210
leaq 0x18(%rsp), %rdi
callq 0x4210
jmp 0x356f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x10(%rsp)
movl %eax, 0xc(%rsp)
jmp 0x356e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x10(%rsp)
movl %eax, 0xc(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x4210
leaq 0x18(%rsp), %rdi
callq 0x4210
jmp 0x35710
movq 0x70(%rsp), %rax
movl 0x14(%rax), %eax
movl %eax, 0xa4(%rsp)
movl 0xa4(%rsp), %eax
addq $0xa8, %rsp
retq
movq 0x10(%rsp), %rdi
callq 0x4660
nopw (%rax,%rax)