// File: 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:
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rdi, 0x1f0(%rsp)
movq %rsi, 0x1e8(%rsp)
movq 0x1f0(%rsp), %rdi
movq %rdi, 0x38(%rsp)
addq $0x54f0, %rdi           # imm = 0x54F0
callq 0x1a920
movq 0x38(%rsp), %rax
movq 0x4110(%rax), %rcx
movq %rcx, 0x1e0(%rsp)
testb $0x1, 0xa1(%rax)
je 0x18663
movq 0x38(%rsp), %rdi
addq $0x40e0, %rdi           # imm = 0x40E0
addq $0x28, %rdi
callq 0x1a560
cmpl $0x0, %eax
jbe 0x18663
leaq 0x1b0(%rsp), %rdi
callq 0x1b5a0
movq 0x38(%rsp), %rdi
addq $0x4108, %rdi           # imm = 0x4108
callq 0x1c340
movq %rax, 0x30(%rsp)
jmp 0x18204
movq 0x30(%rsp), %rax
movq %rax, 0x1a8(%rsp)
movq 0x38(%rsp), %rdi
movq 0x1a8(%rsp), %rax
movq %rax, 0x20(%rsp)
addq $0x4108, %rdi           # imm = 0x4108
callq 0x1c390
movq %rax, 0x28(%rsp)
jmp 0x18236
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
cmpq %rcx, %rax
je 0x182d6
movq 0x1a8(%rsp), %rdi
addq $0x24, %rdi
movq 0x1e8(%rsp), %rsi
callq 0x1c3e0
movb %al, 0x1f(%rsp)
jmp 0x18268
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x18272
jmp 0x182bb
movq 0x1a8(%rsp), %rsi
leaq 0x1b0(%rsp), %rdi
callq 0x1c1d0
jmp 0x18289
movq 0x1a8(%rsp), %rsi
leaq 0x1b0(%rsp), %rdi
callq 0x1c430
jmp 0x182a0
jmp 0x182d6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0x18651
jmp 0x182bd
movq 0x1a8(%rsp), %rax
addq $0x30, %rax
movq %rax, 0x1a8(%rsp)
jmp 0x18211
movq 0x38(%rsp), %rsi
movq %rsi, %rdi
addq $0x40e0, %rdi           # imm = 0x40E0
addq $0x4130, %rsi           # imm = 0x4130
callq 0x1bb20
movl %eax, 0x18(%rsp)
jmp 0x182f7
movq 0x38(%rsp), %rdi
movl 0x18(%rsp), %eax
movl %eax, %eax
movl %eax, %ecx
movq 0x4110(%rdi), %rax
subq %rcx, %rax
movq %rax, 0x4110(%rdi)
addq $0x40e0, %rdi           # imm = 0x40E0
leaq 0x1b0(%rsp), %rsi
callq 0x1c1d0
jmp 0x1832b
movq 0x38(%rsp), %rdi
addq $0x40e0, %rdi           # imm = 0x40E0
leaq 0x1b0(%rsp), %rsi
callq 0x1c430
jmp 0x18346
cmpq $0x0, 0x1e0(%rsp)
jbe 0x1863f
movq 0x1e0(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
callq 0x1a9f0
jmp 0x1836c
leaq 0x36a6f(%rip), %rsi     # 0x4ede2
leaq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rdx
callq 0x19f30
jmp 0x1838a
leaq 0x3501f(%rip), %rdx     # 0x4d3b0
leaq 0xf8(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0xb910
jmp 0x183a8
movq 0x38(%rsp), %rax
movq 0x4110(%rax), %rsi
leaq 0x98(%rsp), %rdi
callq 0x1a9f0
jmp 0x183c3
leaq 0x118(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
leaq 0x98(%rsp), %rdx
callq 0x19e40
jmp 0x183e2
leaq 0x34fd1(%rip), %rdx     # 0x4d3ba
leaq 0x138(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0xb910
jmp 0x18400
movq 0x38(%rsp), %rax
vcvtusi2sdq 0x4110(%rax), %xmm0, %xmm0
vmovsd 0x34dc1(%rip), %xmm1    # 0x4d1d8
vmulsd %xmm1, %xmm0, %xmm0
vcvtusi2sdq 0x1e0(%rsp), %xmm1, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
leaq 0x78(%rsp), %rdi
movl $0x1, %esi
callq 0x48780
jmp 0x18438
leaq 0x158(%rsp), %rdi
leaq 0x138(%rsp), %rsi
leaq 0x78(%rsp), %rdx
callq 0x19e40
jmp 0x18454
leaq 0x34f68(%rip), %rdx     # 0x4d3c3
leaq 0x178(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0xb910
jmp 0x18472
leaq 0x178(%rsp), %rdi
callq 0x1a9b0
jmp 0x18481
leaq 0x178(%rsp), %rdi
callq 0x5260
leaq 0x158(%rsp), %rdi
callq 0x5260
leaq 0x78(%rsp), %rdi
callq 0x5260
leaq 0x138(%rsp), %rdi
callq 0x5260
leaq 0x118(%rsp), %rdi
callq 0x5260
leaq 0x98(%rsp), %rdi
callq 0x5260
leaq 0xf8(%rsp), %rdi
callq 0x5260
leaq 0xd8(%rsp), %rdi
callq 0x5260
leaq 0xb8(%rsp), %rdi
callq 0x5260
jmp 0x1863f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0x18630
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0x18623
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0x18616
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0x18609
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0x185fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0x185ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0x185e5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
jmp 0x185d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x5260
leaq 0x158(%rsp), %rdi
callq 0x5260
leaq 0x78(%rsp), %rdi
callq 0x5260
leaq 0x138(%rsp), %rdi
callq 0x5260
leaq 0x118(%rsp), %rdi
callq 0x5260
leaq 0x98(%rsp), %rdi
callq 0x5260
leaq 0xf8(%rsp), %rdi
callq 0x5260
leaq 0xd8(%rsp), %rdi
callq 0x5260
leaq 0xb8(%rsp), %rdi
callq 0x5260
jmp 0x18651
leaq 0x1b0(%rsp), %rdi
callq 0x1bab0
jmp 0x18705
leaq 0x1b0(%rsp), %rdi
callq 0x1bab0
jmp 0x187f2
movq 0x38(%rsp), %rsi
movq %rsi, %rdi
addq $0x40e0, %rdi           # imm = 0x40E0
movq %rdi, 0x8(%rsp)
addq $0x4130, %rsi           # imm = 0x4130
callq 0x1bb20
movl %eax, %ecx
movq 0x38(%rsp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x4110(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x4110(%rax)
leaq 0x48(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x1b5a0
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x1c1d0
jmp 0x186bf
leaq 0x48(%rsp), %rdi
callq 0x1bab0
movq 0x38(%rsp), %rax
movq 0x1e8(%rsp), %rcx
movw (%rcx), %cx
movw %cx, 0x4104(%rax)
jmp 0x18705
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a0(%rsp)
movl %eax, 0x19c(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x1bab0
jmp 0x187f2
movq 0x38(%rsp), %rdi
movq 0x4110(%rdi), %rax
movq %rax, (%rsp)
addq $0x40e0, %rdi           # imm = 0x40E0
callq 0x1c460
movl %eax, %ecx
movq (%rsp), %rax
movl %ecx, %ecx
cmpq %rcx, %rax
jne 0x18730
jmp 0x1874f
leaq 0x34c9b(%rip), %rdi     # 0x4d3d2
leaq 0x34ca9(%rip), %rsi     # 0x4d3e7
movl $0xfd, %edx
leaq 0x34caf(%rip), %rcx     # 0x4d3f9
callq 0x52a0
movq 0x38(%rsp), %rdi
addq $0x10, %rdi
movq 0x1e8(%rsp), %rsi
movl $0x1, %ecx
movl %ecx, %edx
callq 0x1c500
movq 0x38(%rsp), %rax
movq %rax, %rdi
addq $0x40e0, %rdi           # imm = 0x40E0
addq $0x10, %rdi
movl 0xa8(%rax), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x1c2a0
movq 0x38(%rsp), %rdi
addq $0x10, %rdi
callq 0x1a900
movb %al, 0x47(%rsp)
leaq 0x47(%rsp), %rdi
leaq 0x54d14(%rip), %rsi     # 0x6d4c3
callq 0x1b520
testb $0x1, %al
jne 0x187ba
jmp 0x187ce
movq 0x38(%rsp), %rax
leaq 0x54cfa(%rip), %rcx     # 0x6d4c0
movb (%rcx), %cl
movb %cl, 0x4102(%rax)
movq 0x38(%rsp), %rax
testb $0x1, 0x58(%rax)
je 0x187ea
movq 0x38(%rsp), %rdi
addq $0x54f0, %rdi           # imm = 0x54F0
callq 0x1ab60
addq $0x1f8, %rsp            # imm = 0x1F8
retq
movq 0x1a0(%rsp), %rdi
callq 0x5760
nop