// File: 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:
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rdi, 0x1e0(%rsp)
movq %rsi, 0x1d8(%rsp)
movq 0x1e0(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x2aaa0
movq 0x38(%rsp), %rax
movq 0xd0(%rax), %rcx
movq %rcx, 0x1d0(%rsp)
testb $0x1, 0x60(%rax)
je 0x2ba56
movq 0x38(%rsp), %rdi
addq $0xa8, %rdi
addq $0x20, %rdi
callq 0x2dc00
cmpl $0x0, %eax
jbe 0x2ba56
leaq 0x1a8(%rsp), %rdi
callq 0x2d560
movq 0x38(%rsp), %rdi
addq $0xc8, %rdi
callq 0x2dc40
movq %rax, 0x30(%rsp)
jmp 0x2b5fa
movq 0x30(%rsp), %rax
movq %rax, 0x1a0(%rsp)
movq 0x38(%rsp), %rdi
movq 0x1a0(%rsp), %rax
movq %rax, 0x20(%rsp)
addq $0xc8, %rdi
callq 0x2dc90
movq %rax, 0x28(%rsp)
jmp 0x2b62c
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
cmpq %rcx, %rax
je 0x2b6cc
movq 0x1a0(%rsp), %rdi
addq $0x14, %rdi
movq 0x1d8(%rsp), %rsi
callq 0x285a0
movb %al, 0x1f(%rsp)
jmp 0x2b65e
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x2b668
jmp 0x2b6b1
movq 0x1a0(%rsp), %rsi
leaq 0x1a8(%rsp), %rdi
callq 0x2db10
jmp 0x2b67f
movq 0x1a0(%rsp), %rsi
leaq 0x1a8(%rsp), %rdi
callq 0x2dce0
jmp 0x2b696
jmp 0x2b6cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x2ba44
jmp 0x2b6b3
movq 0x1a0(%rsp), %rax
addq $0x28, %rax
movq %rax, 0x1a0(%rsp)
jmp 0x2b607
movq 0x38(%rsp), %rsi
movq %rsi, %rdi
addq $0xa8, %rdi
addq $0xf0, %rsi
callq 0x2d7c0
movl %eax, 0x18(%rsp)
jmp 0x2b6ed
movq 0x38(%rsp), %rdi
movl 0x18(%rsp), %eax
movl %eax, %eax
movl %eax, %ecx
movq 0xd0(%rdi), %rax
subq %rcx, %rax
movq %rax, 0xd0(%rdi)
addq $0xa8, %rdi
leaq 0x1a8(%rsp), %rsi
callq 0x2db10
jmp 0x2b721
movq 0x38(%rsp), %rdi
addq $0xa8, %rdi
leaq 0x1a8(%rsp), %rsi
callq 0x2dce0
jmp 0x2b73c
cmpq $0x0, 0x1d0(%rsp)
jbe 0x2ba32
movq 0x1d0(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x161a0
jmp 0x2b762
leaq 0x15184(%rip), %rsi     # 0x408ed
leaq 0xd0(%rsp), %rdi
leaq 0xb0(%rsp), %rdx
callq 0xe5f0
jmp 0x2b780
leaq 0x1517c(%rip), %rdx     # 0x40903
leaq 0xf0(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x93b0
jmp 0x2b79e
movq 0x38(%rsp), %rax
movq 0xd0(%rax), %rsi
leaq 0x90(%rsp), %rdi
callq 0x161a0
jmp 0x2b7b9
leaq 0x110(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0xe470
jmp 0x2b7d8
leaq 0x1512e(%rip), %rdx     # 0x4090d
leaq 0x130(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x93b0
jmp 0x2b7f6
movq 0x38(%rsp), %rax
vcvtusi2sdq 0xd0(%rax), %xmm0, %xmm0
vmovsd 0x12a8e(%rip), %xmm1    # 0x3e298
vmulsd %xmm1, %xmm0, %xmm0
vcvtusi2sdq 0x1d0(%rsp), %xmm1, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
leaq 0x70(%rsp), %rdi
movl $0x1, %esi
callq 0x1e870
jmp 0x2b82b
leaq 0x150(%rsp), %rdi
leaq 0x130(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0xe470
jmp 0x2b847
leaq 0x150c8(%rip), %rdx     # 0x40916
leaq 0x170(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x93b0
jmp 0x2b865
leaq 0x170(%rsp), %rdi
callq 0x15ad0
jmp 0x2b874
leaq 0x170(%rsp), %rdi
callq 0x4210
leaq 0x150(%rsp), %rdi
callq 0x4210
leaq 0x70(%rsp), %rdi
callq 0x4210
leaq 0x130(%rsp), %rdi
callq 0x4210
leaq 0x110(%rsp), %rdi
callq 0x4210
leaq 0x90(%rsp), %rdi
callq 0x4210
leaq 0xf0(%rsp), %rdi
callq 0x4210
leaq 0xd0(%rsp), %rdi
callq 0x4210
leaq 0xb0(%rsp), %rdi
callq 0x4210
jmp 0x2ba32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x2ba23
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x2ba16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x2ba09
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x2b9fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x2b9ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x2b9e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x2b9d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x2b9cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x4210
leaq 0x150(%rsp), %rdi
callq 0x4210
leaq 0x70(%rsp), %rdi
callq 0x4210
leaq 0x130(%rsp), %rdi
callq 0x4210
leaq 0x110(%rsp), %rdi
callq 0x4210
leaq 0x90(%rsp), %rdi
callq 0x4210
leaq 0xf0(%rsp), %rdi
callq 0x4210
leaq 0xd0(%rsp), %rdi
callq 0x4210
leaq 0xb0(%rsp), %rdi
callq 0x4210
jmp 0x2ba44
leaq 0x1a8(%rsp), %rdi
callq 0x2d750
jmp 0x2baf8
leaq 0x1a8(%rsp), %rdi
callq 0x2d750
jmp 0x2bbc5
movq 0x38(%rsp), %rsi
movq %rsi, %rdi
addq $0xa8, %rdi
movq %rdi, 0x8(%rsp)
addq $0xf0, %rsi
callq 0x2d7c0
movl %eax, %ecx
movq 0x38(%rsp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0xd0(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0xd0(%rax)
leaq 0x48(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x2d560
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x2db10
jmp 0x2bab2
leaq 0x48(%rsp), %rdi
callq 0x2d750
movq 0x38(%rsp), %rax
movq 0x1d8(%rsp), %rcx
movw (%rcx), %cx
movw %cx, 0xbc(%rax)
jmp 0x2baf8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x2d750
jmp 0x2bbc5
movq 0x38(%rsp), %rdi
movq 0xd0(%rdi), %rax
movq %rax, (%rsp)
addq $0xa8, %rdi
callq 0x2dd10
movl %eax, %ecx
movq (%rsp), %rax
movl %ecx, %ecx
cmpq %rcx, %rax
jne 0x2bb23
jmp 0x2bb42
leaq 0x14dfb(%rip), %rdi     # 0x40925
leaq 0x14ba1(%rip), %rsi     # 0x406d2
movl $0x12f, %edx            # imm = 0x12F
leaq 0x14dfd(%rip), %rcx     # 0x4093a
callq 0x4250
movq 0x38(%rsp), %rdi
addq $0x80, %rdi
movq 0x1d8(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x44(%rsp)
movl 0x44(%rsp), %esi
callq 0xd040
movq 0x38(%rsp), %rax
movq %rax, %rdi
addq $0xa8, %rdi
movl 0x68(%rax), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x2dbd0
movq 0x38(%rsp), %rdi
addq $0x80, %rdi
callq 0x15fb0
movsbl %al, %eax
cmpl $0x0, %eax
jge 0x2bba8
movq 0x38(%rsp), %rax
movb $-0x3, 0xba(%rax)
movq 0x38(%rsp), %rax
testb $0x1, 0x38(%rax)
je 0x2bbbd
movq 0x38(%rsp), %rdi
callq 0x2ab40
addq $0x1e8, %rsp            # imm = 0x1E8
retq
movq 0x198(%rsp), %rdi
callq 0x4660
nopw %cs:(%rax,%rax)