// File: /workspace/github_cpp_makefile_star2_O2/tewalds[P]morat/hex/agentmcts.cpp
// Function: Morat::Hex::AgentMCTS::move(Morat::Move const&)
void AgentMCTS::move(const Move & m){
	pool.pause();

	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.outcome() < Outcome::DRAW)
		root.outcome = Outcome::UNKNOWN;

	if(ponder)
		pool.resume();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
leaq 0x54f0(%rdi), %rbx
movq %rdi, %r14
movq %rsi, %r15
movq %rbx, %rdi
callq 0xd3e6
cmpb $0x1, 0xa1(%r14)
jne 0xbf47
movq 0x4108(%r14), %r13
cmpq $0x2, %r13
jb 0xbf47
cmpw $0x0, 0x6(%r13)
je 0xbf47
movq 0x4110(%r14), %rax
leaq 0x48(%rsp), %rbp
vxorpd %xmm0, %xmm0, %xmm0
leaq 0x40e0(%r14), %rsi
leaq 0x4108(%r14), %rdx
xorl %r12d, %r12d
vmovupd %ymm0, -0x28(%rbp)
andw $0x0, -0x8(%rbp)
movq %rsi, 0x18(%rsp)
movq %rdx, 0x8(%rsp)
leaq 0x10(%r13), %rsi
leaq 0x35(%r13), %rdx
movq %rax, 0x10(%rsp)
leaq 0x1afac(%rip), %rax     # 0x26eae
movb (%rax), %al
movb %al, -0x6(%rbp)
movl $0xfc78fd00, -0x5(%rbp) # imm = 0xFC78FD00
movb $0x78, -0x1(%rbp)
andq $0x0, (%rbp)
movzwl 0x6(%r13), %edi
movb (%r15), %al
movb 0x1(%r15), %cl
imulq $-0x30, %rdi, %rdi
cmpq %r12, %rdi
je 0xc072
cmpb %al, -0x1(%rdx)
jne 0xbf3d
cmpb %cl, (%rdx)
je 0xc050
addq $-0x30, %r12
addq $0x30, %rdx
jmp 0xbf27
leaq 0x40e0(%r14), %r12
leaq 0x4130(%r14), %rsi
movq %r12, %rdi
callq 0xdcb0
movl %eax, %eax
subq %rax, 0x4110(%r14)
leaq 0x1af41(%rip), %rax     # 0x26eae
leaq 0x20(%rsp), %rsi
vxorpd %xmm0, %xmm0, %xmm0
vmovupd %ymm0, (%rsi)
andw $0x0, 0x20(%rsi)
movb (%rax), %al
movb %al, 0x22(%rsi)
movl $0xfc78fd00, 0x23(%rsi) # imm = 0xFC78FD00
movb $0x78, 0x27(%rsi)
andq $0x0, 0x28(%rsi)
movq %r12, %rdi
vzeroupper
callq 0xe0da
leaq 0x20(%rsp), %rdi
callq 0xdc78
movzwl (%r15), %eax
movw %ax, 0x4104(%r14)
movq 0x4110(%r14), %r12
leaq 0x40e0(%r14), %rdi
callq 0xe194
movl %eax, %eax
cmpq %rax, %r12
jne 0xc231
leaq 0x10(%r14), %rdi
pushq $0x1
popq %rcx
movq %r15, %rsi
movl %ecx, %edx
callq 0xe1ea
movl 0xa8(%r14), %eax
leaq 0x1aebf(%rip), %rcx     # 0x26eb1
incl %eax
vmovq %rax, %xmm0
addq %rax, %rax
vmovq %rax, %xmm1
vpunpcklqdq %xmm0, %xmm1, %xmm0 # xmm0 = xmm1[0],xmm0[0]
vpaddq 0x40f0(%r14), %xmm0, %xmm0
vmovdqu %xmm0, 0x40f0(%r14)
movb 0x19(%r14), %al
cmpb (%rcx), %al
jge 0xc02f
leaq 0x1ae88(%rip), %rax     # 0x26eae
movb (%rax), %al
movb %al, 0x4102(%r14)
cmpb $0x1, 0x58(%r14)
jne 0xc03e
movq %rbx, %rdi
callq 0xd534
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subq %r12, %rsi
leaq 0x20(%rsp), %rdi
vzeroupper
callq 0xe0da
subq %r12, %r13
movq %rbp, %rdi
addq $0x38, %r13
movq %r13, %rsi
callq 0xef10
leaq 0x4130(%r14), %rsi
movq 0x18(%rsp), %r12
movq %r12, %rdi
vzeroupper
callq 0xdcb0
movl %eax, %eax
subq %rax, 0x4110(%r14)
leaq 0x20(%rsp), %rsi
movq %r12, %rdi
callq 0xe0da
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0xef10
movq 0x10(%rsp), %r12
testq %r12, %r12
je 0xc222
leaq 0x98(%rsp), %rdi
movq %r12, %rsi
callq 0xd463
leaq 0x18c51(%rip), %rsi     # 0x24d22
leaq 0xb8(%rsp), %rdi
leaq 0x98(%rsp), %rdx
callq 0xcf8b
leaq 0x172ff(%rip), %rdx     # 0x233ec
leaq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x8051
movq 0x4110(%r14), %rsi
leaq 0x78(%rsp), %rdi
callq 0xd463
leaq 0xf8(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
leaq 0x78(%rsp), %rdx
callq 0xcf24
leaq 0x172c2(%rip), %rdx     # 0x233f6
leaq 0x118(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x8051
vcvtusi2sdq 0x4110(%r14), %xmm1, %xmm0
vmulsd 0x1707d(%rip), %xmm0, %xmm0 # 0x231d8
vcvtusi2sd %r12, %xmm1, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
leaq 0x58(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x20e6c
leaq 0x138(%rsp), %rdi
leaq 0x118(%rsp), %rsi
leaq 0x58(%rsp), %rdx
callq 0xcf24
leaq 0x1726c(%rip), %rdx     # 0x233ff
leaq 0x158(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x8051
leaq 0x158(%rsp), %r12
movq %r12, %rdi
callq 0xd451
movq %r12, %rdi
callq 0x5150
leaq 0x138(%rsp), %rdi
callq 0x5150
leaq 0x58(%rsp), %rdi
callq 0x5150
leaq 0x118(%rsp), %rdi
callq 0x5150
leaq 0xf8(%rsp), %rdi
callq 0x5150
leaq 0x78(%rsp), %rdi
callq 0x5150
leaq 0xd8(%rsp), %rdi
callq 0x5150
leaq 0xb8(%rsp), %rdi
callq 0x5150
leaq 0x98(%rsp), %rdi
callq 0x5150
leaq 0x20(%rsp), %rdi
callq 0xdc78
jmp 0xbfb5
leaq 0x171d6(%rip), %rdi     # 0x2340e
leaq 0x171e4(%rip), %rsi     # 0x23423
leaq 0x171ef(%rip), %rcx     # 0x23435
movl $0xfd, %edx
callq 0x51f0
jmp 0xc2e3
leaq 0x138(%rsp), %rdi
movq %rax, %rbx
callq 0x5150
jmp 0xc26a
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x5150
jmp 0xc279
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
callq 0x5150
jmp 0xc28b
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x5150
jmp 0xc29d
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x5150
leaq 0xd8(%rsp), %rdi
callq 0x5150
leaq 0xb8(%rsp), %rdi
callq 0x5150
leaq 0x98(%rsp), %rdi
callq 0x5150
jmp 0xc2e6
movq %rax, %rbx
jmp 0xc2a7
movq %rax, %rbx
jmp 0xc2b4
movq %rax, %rbx
jmp 0xc2c1
jmp 0xc2e3
jmp 0xc2e3
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xdc78
movq %rbx, %rdi
callq 0x5650