// File: /workspace/github_cpp_makefile_star2_O2/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 $0x158, %rsp            # imm = 0x158
movq %rsi, %r14
movq %rdi, %rbx
callq 0x13fda
cmpb $0x1, 0x60(%rbx)
jne 0x14683
movq 0xc8(%rbx), %r15
cmpq $0x2, %r15
jb 0x14683
cmpw $0x0, 0x6(%r15)
je 0x14683
movq 0xd0(%rbx), %rax
leaq 0x30(%rsp), %r13
vxorpd %xmm0, %xmm0, %xmm0
leaq 0xa8(%rbx), %rbp
leaq 0x10(%r15), %rsi
leaq 0x24(%r15), %rcx
xorl %r12d, %r12d
vmovapd %xmm0, -0x20(%r13)
movl $0xfd0000, -0x10(%r13)  # imm = 0xFD0000
movq %rax, 0x8(%rsp)
leaq 0xc8(%rbx), %rax
movq %rax, (%rsp)
movw $0x8efc, %ax            # imm = 0x8EFC
movw %ax, -0xc(%r13)
movw %ax, -0x8(%r13)
andq $0x0, (%r13)
movzwl 0x6(%r15), %edx
movzwl (%r14), %eax
imulq $-0x28, %rdx, %rdx
cmpq %r12, %rdx
je 0x1478c
cmpw %ax, (%rcx)
je 0x1476d
addq $-0x28, %r12
addq $0x28, %rcx
jmp 0x14667
leaq 0xa8(%rbx), %r15
leaq 0xf0(%rbx), %rsi
movq %r15, %rdi
callq 0x1580e
vxorpd %xmm0, %xmm0, %xmm0
leaq 0x10(%rsp), %rsi
movw $0x8efc, %cx            # imm = 0x8EFC
movl %eax, %eax
subq %rax, 0xd0(%rbx)
vmovapd %xmm0, (%rsi)
movl $0xfd0000, 0x10(%rsi)   # imm = 0xFD0000
movw %cx, 0x14(%rsi)
movw %cx, 0x18(%rsi)
andq $0x0, 0x20(%rsi)
movq %r15, %rdi
callq 0x159f6
leaq 0x10(%rsp), %rdi
callq 0x157d4
movzwl (%r14), %eax
movw %ax, 0xbc(%rbx)
movq 0xd0(%rbx), %r15
leaq 0xa8(%rbx), %rdi
callq 0x15a5a
movl %eax, %eax
cmpq %rax, %r15
jne 0x14936
movl (%r14), %esi
leaq 0x80(%rbx), %r15
movq %r15, %rdi
callq 0x7ada
movl 0x68(%rbx), %eax
movq %r15, %rdi
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)
callq 0xae70
testb %al, %al
jns 0x1474d
movb $-0x3, 0xba(%rbx)
cmpb $0x1, 0x38(%rbx)
jne 0x1475b
movq %rbx, %rdi
callq 0x14036
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subq %r12, %rsi
leaq 0x10(%rsp), %rdi
callq 0x159f6
subq %r12, %r15
movq %r13, %rdi
addq $0x30, %r15
movq %r15, %rsi
callq 0x165b8
leaq 0xf0(%rbx), %rsi
movq %rbp, %rdi
callq 0x1580e
movl %eax, %eax
subq %rax, 0xd0(%rbx)
leaq 0x10(%rsp), %rsi
movq %rbp, %rdi
callq 0x159f6
movq (%rsp), %rdi
movq %r13, %rsi
callq 0x165b8
movq 0x8(%rsp), %r15
testq %r15, %r15
je 0x14927
leaq 0x78(%rsp), %rdi
movq %r15, %rsi
callq 0xaf8f
leaq 0xb10e(%rip), %rsi      # 0x1f8ed
leaq 0x98(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x8423
leaq 0xb10b(%rip), %rdx      # 0x1f903
leaq 0xb8(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x6821
movq 0xd0(%rbx), %rsi
leaq 0x58(%rsp), %rdi
callq 0xaf8f
leaq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
leaq 0x58(%rsp), %rdx
callq 0x8365
leaq 0xb0ce(%rip), %rdx      # 0x1f90d
leaq 0xf8(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x6821
vcvtusi2sdq 0xd0(%rbx), %xmm1, %xmm0
vmulsd 0x8a45(%rip), %xmm0, %xmm0 # 0x1d2a8
vcvtusi2sd %r15, %xmm1, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
leaq 0x38(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0xf350
leaq 0x118(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
leaq 0x38(%rsp), %rdx
callq 0x8365
leaq 0xb07b(%rip), %rdx      # 0x1f916
leaq 0x138(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x6821
leaq 0x138(%rsp), %r15
movq %r15, %rdi
callq 0xac65
movq %r15, %rdi
callq 0x4130
leaq 0x118(%rsp), %rdi
callq 0x4130
leaq 0x38(%rsp), %rdi
callq 0x4130
leaq 0xf8(%rsp), %rdi
callq 0x4130
leaq 0xd8(%rsp), %rdi
callq 0x4130
leaq 0x58(%rsp), %rdi
callq 0x4130
leaq 0xb8(%rsp), %rdi
callq 0x4130
leaq 0x98(%rsp), %rdi
callq 0x4130
leaq 0x78(%rsp), %rdi
callq 0x4130
leaq 0x10(%rsp), %rdi
callq 0x157d4
jmp 0x146e4
leaq 0xafe8(%rip), %rdi      # 0x1f925
leaq 0xad8e(%rip), %rsi      # 0x1f6d2
leaq 0xafef(%rip), %rcx      # 0x1f93a
movl $0x12f, %edx            # imm = 0x12F
callq 0x41c0
jmp 0x149e5
leaq 0x118(%rsp), %rdi
movq %rax, %rbx
callq 0x4130
jmp 0x1496f
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x4130
jmp 0x1497e
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x4130
jmp 0x14990
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x4130
jmp 0x149a2
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x4130
leaq 0xb8(%rsp), %rdi
callq 0x4130
leaq 0x98(%rsp), %rdi
callq 0x4130
leaq 0x78(%rsp), %rdi
callq 0x4130
jmp 0x149e8
movq %rax, %rbx
jmp 0x149ac
movq %rax, %rbx
jmp 0x149b9
movq %rax, %rbx
jmp 0x149c6
jmp 0x149e5
jmp 0x149e5
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x157d4
movq %rbx, %rdi
callq 0x4590