// File: /workspace/github_cpp_makefile_star2_O1/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 0x1ce14
cmpb $0x1, 0x60(%rbx)
jne 0x1d54c
movq 0xc8(%rbx), %rax
cmpq $0x2, %rax
jb 0x1d54c
cmpw $0x0, 0x6(%rax)
je 0x1d54c
movq 0xd0(%rbx), %r15
leaq 0xa8(%rbx), %r12
leaq 0x10(%rax), %rcx
xorl %ebp, %ebp
cmpq $0x2, %rax
vxorpd %xmm0, %xmm0, %xmm0
leaq 0x20(%rsp), %r13
vmovapd %xmm0, -0x20(%r13)
movl $0xfd0000, -0x10(%r13)  # imm = 0xFD0000
movw $0x8efc, %dx            # imm = 0x8EFC
movw %dx, -0xc(%r13)
movw %dx, -0x8(%r13)
movq %rbp, (%r13)
cmovaeq %rcx, %rbp
movzwl (%r14), %edx
addq $0x20, %rbp
cmpq $0x2, %rax
jb 0x1d52d
movzwl 0x6(%rax), %esi
leaq (%rsi,%rsi,4), %rsi
leaq (%rcx,%rsi,8), %rdi
jmp 0x1d52f
xorl %edi, %edi
leaq -0x20(%rbp), %rsi
cmpq %rdi, %rsi
je 0x1d680
cmpw %dx, -0xc(%rbp)
je 0x1d649
addq $0x28, %rbp
jmp 0x1d519
leaq 0xa8(%rbx), %r15
leaq 0xf0(%rbx), %rsi
movq %r15, %rdi
callq 0x1f2c2
movl %eax, %eax
subq %rax, 0xd0(%rbx)
vxorpd %xmm0, %xmm0, %xmm0
movq %rsp, %rsi
vmovapd %xmm0, (%rsi)
movl $0xfd0000, 0x10(%rsi)   # imm = 0xFD0000
movw $0x8efc, %ax            # imm = 0x8EFC
movw %ax, 0x14(%rsi)
movw %ax, 0x18(%rsi)
movq $0x0, 0x20(%rsi)
movq %r15, %rdi
callq 0x1f57c
movq %rsp, %rdi
callq 0x1f26a
movzwl (%r14), %eax
movw %ax, 0xbc(%rbx)
movq 0xd0(%rbx), %r15
leaq 0xa8(%rbx), %rdi
callq 0x1f5e2
movl %eax, %eax
cmpq %rax, %r15
jne 0x1db1c
leaq 0x80(%rbx), %r15
movl (%r14), %esi
movq %r15, %rdi
callq 0x9240
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)
cmpb $-0x4, 0x9a(%rbx)
jne 0x1d619
movq %r15, %rdi
callq 0xdab0
movb %al, 0x9a(%rbx)
cmpb $0x0, 0x9a(%rbx)
jns 0x1d629
movb $-0x3, 0xba(%rbx)
cmpb $0x1, 0x38(%rbx)
jne 0x1d637
movq %rbx, %rdi
callq 0x1ce74
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsp, %rdi
callq 0x1f57c
movq 0x20(%rsp), %rax
movq (%rbp), %rcx
movq %rcx, 0x20(%rsp)
movq %rax, (%rbp)
movq 0x20(%rsp), %rax
cmpq $0x2, %rax
jb 0x1d672
movq %r13, 0x8(%rax)
movq (%rbp), %rax
cmpq $0x2, %rax
jb 0x1d680
movq %rbp, 0x8(%rax)
leaq 0xf0(%rbx), %rsi
movq %r12, %rdi
callq 0x1f2c2
movl %eax, %eax
subq %rax, 0xd0(%rbx)
movq %rsp, %rsi
movq %r12, %rdi
callq 0x1f57c
movq 0xc8(%rbx), %rcx
movq 0x20(%rsp), %rax
movq %rax, 0xc8(%rbx)
movq %rcx, 0x20(%rsp)
cmpq $0x2, %rax
jb 0x1d6cc
leaq 0xc8(%rbx), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rsp), %rax
cmpq $0x2, %rax
jb 0x1d6db
movq %r13, 0x8(%rax)
testq %r15, %r15
jne 0x1d6ed
movq %rsp, %rdi
callq 0x1f26a
jmp 0x1d5ac
leaq 0x128(%rsp), %rdi
movq %r15, %rsi
callq 0xd669
leaq 0xf285(%rip), %rcx      # 0x2c989
leaq 0x128(%rsp), %rdi
movl $0x15, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x4330
leaq 0xf8(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x1d743
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%r12)
jmp 0x1d756
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 0xf223(%rip), %rsi      # 0x2c99f
callq 0x4610
leaq 0x78(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x1d7a5
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%r13)
jmp 0x1d7b2
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 0xd669
movq 0x68(%rsp), %rcx
movq 0x70(%rsp), %r8
movq 0xd0(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %esi
cmpq %r13, %rcx
je 0x1d803
movq 0x78(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x1d828
leaq 0xd8(%rsp), %rdi
movl $0xf, %esi
cmpq %rdi, -0x10(%rdi)
je 0x1d823
movq 0xd8(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x1d83c
movq 0xc8(%rsp), %rsi
leaq 0x68(%rsp), %rdi
callq 0x40b0
jmp 0x1d84d
leaq 0xc8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4330
leaq 0x38(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
leaq 0x10(%rax), %rcx
cmpq %rcx, %rsi
jne 0x1d86c
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%rdx)
jmp 0x1d879
movq %rsi, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x30(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0xf10c(%rip), %rsi      # 0x2c9a9
leaq 0x28(%rsp), %rdi
callq 0x4610
leaq 0x98(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x1d8cd
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%rbp)
jmp 0x1d8e0
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 0xc9de(%rip), %xmm0, %xmm0 # 0x2a2e8
vcvtusi2sd %r15, %xmm1, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
leaq 0xa8(%rsp), %rdi
movl $0x1, %esi
callq 0x1579c
movq 0x88(%rsp), %rcx
movq 0x90(%rsp), %r8
movq 0xb0(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %esi
cmpq %rbp, %rcx
je 0x1d954
movq 0x98(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x1d979
leaq 0xb8(%rsp), %rdi
movl $0xf, %esi
cmpq %rdi, -0x10(%rdi)
je 0x1d974
movq 0xb8(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x1d990
movq 0xa8(%rsp), %rsi
leaq 0x88(%rsp), %rdi
callq 0x40b0
jmp 0x1d9a1
leaq 0xa8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4330
leaq 0x58(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
leaq 0x10(%rax), %rcx
cmpq %rcx, %rsi
jne 0x1d9c0
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%rdx)
jmp 0x1d9cd
movq %rsi, 0x48(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x58(%rsp)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x50(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0xefc1(%rip), %rsi      # 0x2c9b2
leaq 0x48(%rsp), %rdi
callq 0x4610
leaq 0x118(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x1da21
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%r15)
jmp 0x1da34
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 0x1958a(%rip), %rax     # 0x36fe0
movq (%rax), %rsi
movq 0x108(%rsp), %rdi
callq 0x4320
movq 0x108(%rsp), %rdi
cmpq %r15, %rdi
je 0x1da78
callq 0x42b0
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1da8b
callq 0x42b0
leaq 0xb8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1daa1
callq 0x42b0
movq 0x88(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1dab3
callq 0x42b0
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1dac6
callq 0x42b0
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1dadc
callq 0x42b0
movq 0x68(%rsp), %rdi
cmpq %r13, %rdi
je 0x1daeb
callq 0x42b0
movq 0xe8(%rsp), %rdi
cmpq %r12, %rdi
je 0x1dafd
callq 0x42b0
leaq 0x138(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1d6e0
callq 0x42b0
jmp 0x1d6e0
leaq 0xee9e(%rip), %rdi      # 0x2c9c1
leaq 0xec44(%rip), %rsi      # 0x2c76e
leaq 0xeea5(%rip), %rcx      # 0x2c9d6
movl $0x12f, %edx            # imm = 0x12F
callq 0x41b0
jmp 0x1dc07
movq %rax, %rbx
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1db5b
callq 0x42b0
jmp 0x1db5b
movq %rax, %rbx
leaq 0xb8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1db76
callq 0x42b0
jmp 0x1db76
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1db8d
callq 0x42b0
jmp 0x1db8d
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1dba5
callq 0x42b0
jmp 0x1dba5
movq %rax, %rbx
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1dbc0
callq 0x42b0
jmp 0x1dbc0
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %r13, %rdi
je 0x1dbd4
callq 0x42b0
jmp 0x1dbd4
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
cmpq %r12, %rdi
je 0x1dbeb
callq 0x42b0
jmp 0x1dbeb
movq %rax, %rbx
leaq 0x138(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1dc0a
callq 0x42b0
jmp 0x1dc0a
jmp 0x1dc07
jmp 0x1dc07
movq %rax, %rbx
movq %rsp, %rdi
callq 0x1f26a
movq %rbx, %rdi
callq 0x45b0