// File: /workspace/github_cpp_makefile_star2_O3/tewalds[P]pentagod/agentmcts.cpp
// Function: AgentMCTS::move(Move const&)
void AgentMCTS::move(const Move & m){
	stop_threads();

	uword nodesbefore = nodes;

	if(keeptree && root.children.num() > 0){
		Node child;

		for(Node * i = root.children.begin(); i != root.children.end(); i++){
			if(i->move == m){
				child = *i;          //copy the child experience to temp
				child.swap_tree(*i); //move the child tree to temp
				break;
			}
		}

		nodes -= root.dealloc(ctmem);
		root = child;
		root.swap_tree(child);

		if(nodesbefore > 0)
			logerr("Nodes:       before: " + to_str(nodesbefore) + ", after: " + to_str(nodes) + ", saved " +  to_str(100.0*nodes/nodesbefore, 1) + "% of the tree\n");
	}else{
		nodes -= root.dealloc(ctmem);
		root = Node();
		root.move = m;
	}
	assert(nodes == root.size());

	rootboard.move(m);

	root.exp.addwins(visitexpand+1); //+1 to compensate for the virtual loss
	if(rootboard.won() < 0)
		root.outcome = -3;

	if(ponder)
		start_threads();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rsi, %r14
movq %rdi, %rbx
callq 0x1c842
cmpb $0x1, 0x60(%rbx)
jne 0x1cf61
movq 0xc8(%rbx), %r12
cmpq $0x2, %r12
jb 0x1cf61
cmpw $0x0, 0x6(%r12)
je 0x1cf61
vxorpd %xmm0, %xmm0, %xmm0
leaq 0x20(%rsp), %r13
movw $0x8efc, %ax            # imm = 0x8EFC
movq 0xd0(%rbx), %r15
vmovapd %xmm0, -0x20(%r13)
movl $0xfd0000, -0x10(%r13)  # imm = 0xFD0000
movw %ax, -0xc(%r13)
movw %ax, -0x8(%r13)
movq $0x0, (%r13)
movzwl 0x6(%r12), %eax
testq %rax, %rax
je 0x1d096
movzwl (%r14), %ecx
shll $0x3, %eax
addq $0x30, %r12
leaq (%rax,%rax,4), %rax
cmpw %cx, -0xc(%r12)
je 0x1d05a
addq $0x28, %r12
addq $-0x28, %rax
jne 0x1cf46
jmp 0x1d096
leaq 0xa8(%rbx), %r15
leaq 0xf0(%rbx), %rsi
movq %r15, %rdi
callq 0x1ec8c
movl %eax, %eax
subq %rax, 0xd0(%rbx)
movw $0x8efc, %ax            # imm = 0x8EFC
vxorpd %xmm0, %xmm0, %xmm0
movq %rsp, %rsi
movl $0xfd0000, 0x10(%rsi)   # imm = 0xFD0000
vmovapd %xmm0, (%rsi)
movw %ax, 0x14(%rsi)
movw %ax, 0x18(%rsi)
movq $0x0, 0x20(%rsi)
movq %r15, %rdi
callq 0x1ef48
movq %rsp, %rdi
callq 0x1ec34
movzwl (%r14), %eax
movw %ax, 0xbc(%rbx)
movq 0xd0(%rbx), %r15
leaq 0xa8(%rbx), %rdi
callq 0x1efae
movl %eax, %eax
cmpq %rax, %r15
jne 0x1d52f
movl (%r14), %esi
leaq 0x80(%rbx), %r15
movq %r15, %rdi
callq 0x9282
movl 0x68(%rbx), %eax
incl %eax
vmovq %rax, %xmm0
addq %rax, %rax
vmovq %rax, %xmm1
vpunpcklqdq %xmm0, %xmm1, %xmm0 # xmm0 = xmm1[0],xmm0[0]
vpaddq 0xa8(%rbx), %xmm0, %xmm0
vmovdqu %xmm0, 0xa8(%rbx)
movb 0x9a(%rbx), %al
cmpb $-0x4, %al
jne 0x1d02f
movq %r15, %rdi
callq 0xd9e4
movb %al, 0x9a(%rbx)
testb %al, %al
jns 0x1d03a
movb $-0x3, 0xba(%rbx)
cmpb $0x1, 0x38(%rbx)
jne 0x1d048
movq %rbx, %rdi
callq 0x1c8a2
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x20(%r12), %rsi
movq %rsp, %rdi
callq 0x1ef48
movq 0x20(%rsp), %rax
movq (%r12), %rcx
movq %rcx, 0x20(%rsp)
movq %rax, (%r12)
movq 0x20(%rsp), %rcx
cmpq $0x2, %rcx
jb 0x1d08c
movq %r13, 0x8(%rcx)
movq (%r12), %rax
cmpq $0x2, %rax
jb 0x1d096
movq %r12, 0x8(%rax)
leaq 0xa8(%rbx), %r12
leaq 0xf0(%rbx), %rsi
movq %r12, %rdi
callq 0x1ec8c
movl %eax, %eax
subq %rax, 0xd0(%rbx)
movq %rsp, %rsi
movq %r12, %rdi
callq 0x1ef48
leaq 0xc8(%rbx), %rcx
movq 0x20(%rsp), %rdx
movq (%rcx), %rax
movq %rdx, (%rcx)
movq %rax, 0x20(%rsp)
cmpq $0x2, %rdx
jb 0x1d0e6
movq %rcx, 0x8(%rdx)
movq 0x20(%rsp), %rax
cmpq $0x2, %rax
jb 0x1d0f0
movq %r13, 0x8(%rax)
testq %r15, %r15
jne 0x1d102
movq %rsp, %rdi
callq 0x1ec34
jmp 0x1cfc1
leaq 0x128(%rsp), %rdi
movq %r15, %rsi
callq 0xd5e9
leaq 0xe870(%rip), %rcx      # 0x2b989
leaq 0x128(%rsp), %rdi
movl $0x15, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x4330
leaq 0xf8(%rsp), %r12
movq %rax, %rcx
addq $0x10, %rcx
movq %r12, -0x10(%r12)
movq (%rax), %rdx
cmpq %rcx, %rdx
jne 0x1d158
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%r12)
jmp 0x1d16b
movq %rdx, 0xe8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xf8(%rsp)
movq 0x8(%rax), %rdx
leaq 0xe8(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0xe80e(%rip), %rsi      # 0x2b99f
callq 0x4610
leaq 0x78(%rsp), %r13
movq %rax, %rcx
addq $0x10, %rcx
movq %r13, -0x10(%r13)
movq (%rax), %rdx
cmpq %rcx, %rdx
jne 0x1d1ba
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%r13)
jmp 0x1d1c7
movq %rdx, 0x68(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x78(%rsp)
movq 0x8(%rax), %rdx
movq %rdx, 0x70(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0xd0(%rbx), %rsi
leaq 0xc8(%rsp), %rdi
callq 0xd5e9
movq 0x70(%rsp), %r8
movq 0xd0(%rsp), %rdx
movq 0x68(%rsp), %rcx
movl $0xf, %edi
leaq (%rdx,%r8), %rax
cmpq %r13, %rcx
je 0x1d218
movq 0x78(%rsp), %rdi
movq 0xc8(%rsp), %rsi
cmpq %rdi, %rax
jbe 0x1d244
leaq 0xd8(%rsp), %r9
movl $0xf, %edi
cmpq %r9, %rsi
je 0x1d23f
movq 0xd8(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x1d250
leaq 0x68(%rsp), %rdi
callq 0x40b0
jmp 0x1d261
leaq 0xc8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4330
leaq 0x38(%rsp), %rdx
leaq 0x10(%rax), %rcx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
cmpq %rcx, %rsi
jne 0x1d280
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%rdx)
jmp 0x1d28d
movq %rsi, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
movq 0x8(%rax), %rsi
movq %rax, %rdx
addq $0x8, %rdx
movq %rsi, 0x30(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0xe6f8(%rip), %rsi      # 0x2b9a9
leaq 0x28(%rsp), %rdi
callq 0x4610
leaq 0x98(%rsp), %rbp
movq %rax, %rcx
addq $0x10, %rcx
movq %rbp, -0x10(%rbp)
movq (%rax), %rdx
cmpq %rcx, %rdx
jne 0x1d2e1
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%rbp)
jmp 0x1d2f4
movq %rdx, 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)
vcvtusi2sdq 0xd0(%rbx), %xmm1, %xmm0
vmulsd 0xbfba(%rip), %xmm0, %xmm0 # 0x292d8
vcvtusi2sd %r15, %xmm1, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
leaq 0xa8(%rsp), %rdi
movl $0x1, %esi
callq 0x15694
movq 0x90(%rsp), %r8
movq 0xb0(%rsp), %rdx
movq 0x88(%rsp), %rcx
movl $0xf, %edi
leaq (%rdx,%r8), %rax
cmpq %rbp, %rcx
je 0x1d368
movq 0x98(%rsp), %rdi
movq 0xa8(%rsp), %rsi
cmpq %rdi, %rax
jbe 0x1d394
leaq 0xb8(%rsp), %r9
movl $0xf, %edi
cmpq %r9, %rsi
je 0x1d38f
movq 0xb8(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x1d3a3
leaq 0x88(%rsp), %rdi
callq 0x40b0
jmp 0x1d3b4
leaq 0xa8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4330
leaq 0x58(%rsp), %rdx
leaq 0x10(%rax), %rcx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
cmpq %rcx, %rsi
jne 0x1d3d3
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%rdx)
jmp 0x1d3e0
movq %rsi, 0x48(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x58(%rsp)
movq 0x8(%rax), %rsi
movq %rax, %rdx
addq $0x8, %rdx
movq %rsi, 0x50(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0xe5ae(%rip), %rsi      # 0x2b9b2
leaq 0x48(%rsp), %rdi
callq 0x4610
leaq 0x118(%rsp), %r15
movq %rax, %rcx
addq $0x10, %rcx
movq %r15, -0x10(%r15)
movq (%rax), %rdx
cmpq %rcx, %rdx
jne 0x1d434
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%r15)
jmp 0x1d447
movq %rdx, 0x108(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x118(%rsp)
movq 0x8(%rax), %rdx
movq %rdx, 0x110(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x18b77(%rip), %rax     # 0x35fe0
movq 0x108(%rsp), %rdi
movq (%rax), %rsi
callq 0x4320
movq 0x108(%rsp), %rdi
cmpq %r15, %rdi
je 0x1d48b
callq 0x42b0
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1d49e
callq 0x42b0
leaq 0xb8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1d4b4
callq 0x42b0
movq 0x88(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1d4c6
callq 0x42b0
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1d4d9
callq 0x42b0
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1d4ef
callq 0x42b0
movq 0x68(%rsp), %rdi
cmpq %r13, %rdi
je 0x1d4fe
callq 0x42b0
movq 0xe8(%rsp), %rdi
cmpq %r12, %rdi
je 0x1d510
callq 0x42b0
leaq 0x138(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1d0f5
callq 0x42b0
jmp 0x1d0f5
leaq 0xe48b(%rip), %rdi      # 0x2b9c1
leaq 0xe231(%rip), %rsi      # 0x2b76e
leaq 0xe492(%rip), %rcx      # 0x2b9d6
movl $0x12f, %edx            # imm = 0x12F
callq 0x41b0
jmp 0x1d61a
leaq 0x58(%rsp), %rcx
movq %rax, %rbx
movq -0x10(%rcx), %rdi
cmpq %rcx, %rdi
je 0x1d56e
callq 0x42b0
jmp 0x1d56e
movq %rax, %rbx
leaq 0xb8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1d589
callq 0x42b0
jmp 0x1d589
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1d5a0
callq 0x42b0
jmp 0x1d5a0
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1d5b8
callq 0x42b0
jmp 0x1d5b8
movq %rax, %rbx
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1d5d3
callq 0x42b0
jmp 0x1d5d3
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %r13, %rdi
je 0x1d5e7
callq 0x42b0
jmp 0x1d5e7
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
cmpq %r12, %rdi
je 0x1d5fe
callq 0x42b0
jmp 0x1d5fe
movq %rax, %rbx
leaq 0x138(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1d61d
callq 0x42b0
jmp 0x1d61d
jmp 0x1d61a
jmp 0x1d61a
movq %rax, %rbx
movq %rsp, %rdi
callq 0x1ec34
movq %rbx, %rdi
callq 0x45b0
nop