// File: /workspace/github_cpp_makefile_star2_O3/tewalds[P]morat/havannah/agentmctsthread.cpp
// Function: Morat::Havannah::AgentMCTS::AgentThread::rollout(Morat::Havannah::Board&, Morat::Move, int)
Outcome AgentMCTS::AgentThread::rollout(Board & board, Move move, int depth){
	Outcome won;

	if(agent->instantwin)
		instant_wins.rollout_start(board, agent->instantwin);

	random_policy.rollout_start(board);

	//only check rings to the specified depth
	int  checkdepth = (int)agent->checkringdepth;
	//if it's negative, check for that fraction of the remaining moves
	if(agent->checkringdepth < 0)
		checkdepth = (int)ceil(board.moves_remain() * agent->checkringdepth * -1);

	board.perm_rings = agent->ringperm;

	while((won = board.outcome()) < Outcome::DRAW){
		Side turn = board.to_play();

		board.check_rings = (depth < checkdepth);

		move = rollout_choose_move(board, move);

		movelist.addrollout(move, turn);

		assert2(board.move(move, true, false), "\n" + board.to_s(true) + "\n" + move.to_s());
		depth++;
	}

	gamelen.add(depth);

	if(won > Outcome::DRAW)
		win_types[won.to_i() - 1][(int)board.win_type()].add(depth);

	//update the last good reply table
	if(agent->lastgoodreply)
		last_good_reply.rollout_end(board, movelist, won);

	movelist.finishrollout(won);
	return won;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movw %dx, 0x6(%rsp)
movl %ecx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
movq 0x40(%rdi), %rax
movl 0x13c(%rax), %ecx
testl %ecx, %ecx
je 0x1752d
movsbl (%rbx), %edx
imull %ecx, %edx
negl %edx
testl %ecx, %ecx
cmovnsl %ecx, %edx
movl %edx, 0x28d8(%r14)
movl $0x0, 0x28dc(%r14)
movw $0x78fc, 0x28e0(%r14)   # imm = 0x78FC
movl 0x8cc(%r14), %ecx
vxorps %xmm1, %xmm1, %xmm1
movl %ecx, 0x8d0(%r14)
leaq 0x21bc3(%rip), %rcx     # 0x39109
vmovss 0x12c(%rax), %xmm0
movb 0xb(%rbx), %r15b
movb (%rcx), %cl
vucomiss %xmm0, %xmm1
jbe 0x1758c
movswl 0x4(%rbx), %esi
movswl 0x6(%rbx), %edi
cmpb %cl, %r15b
setl %dl
kmovd %edx, %k1
subl %edi, %esi
vcvtsi2ss %esi, %xmm2, %xmm1
vmovss %xmm1, %xmm1, %xmm1 {%k1} {z}
vxorps 0x1e39e(%rip){1to4}, %xmm0, %xmm0 # 0x35920
vmulss %xmm0, %xmm1, %xmm0
vroundss $0xa, %xmm0, %xmm0, %xmm0
movl 0x130(%rax), %eax
movl %eax, 0x9c(%rbx)
cmpb %cl, %r15b
jge 0x17644
vcvttss2si %xmm0, %r12d
leaq 0x12158(%r14), %r13
movb 0xa(%rbx), %r15b
cmpl %r12d, %ebp
leaq 0x6(%rsp), %rdx
movq %r14, %rdi
movq %rbx, %rsi
setl 0x98(%rbx)
callq 0x17c1a
cwtl
movq %rbx, %rdi
movw %ax, 0x6(%rsp)
movslq 0x12598(%r14), %rdx
movslq 0x12594(%r14), %rcx
addq %rdx, %rcx
leal 0x1(%rdx), %esi
leaq (%rcx,%rcx,2), %rcx
movl %esi, 0x12598(%r14)
leaq 0x8(%rsp), %rsi
movw %ax, (%r13,%rcx)
movb %r15b, 0x2(%r13,%rcx)
movsbl %al, %ecx
movsbl (%rbx), %edx
movw %ax, 0x8(%rsp)
sarl $0x8, %eax
imull %ecx, %edx
xorl %ecx, %ecx
addl %edx, %eax
movl $0x1, %edx
movw %ax, 0xa(%rsp)
callq 0x13a24
testb %al, %al
je 0x176d1
movb 0xb(%rbx), %r15b
leaq 0x21ad0(%rip), %rax     # 0x39109
incl %ebp
cmpb (%rax), %r15b
jl 0x175ac
leaq 0x125d0(%r14), %rdi
movl %ebp, %esi
callq 0x17f50
leaq 0x21ab0(%rip), %rax     # 0x39109
cmpb (%rax), %r15b
jle 0x17685
movsbq 0xc(%rbx), %rcx
movsbq %r15b, %rax
movl %ebp, %esi
leaq (%rax,%rax,2), %rax
shlq $0x5, %rax
addq %r14, %rax
shlq $0x5, %rcx
leaq 0x12590(%rcx,%rax), %rdi
callq 0x17f50
movq 0x40(%r14), %rax
movzbl %r15b, %ebp
cmpl $0x0, 0x138(%rax)
je 0x176ab
leaq 0x4c(%r14), %rdi
leaq 0xf418(%r14), %rdx
movq %rbx, %rsi
movl %ebp, %ecx
callq 0x184de
addq $0xf418, %r14           # imm = 0xF418
movl %ebp, %esi
movq %r14, %rdi
callq 0x17e92
movl %r15d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x34918(%rip), %r14     # 0x4bff0
leaq 0x1e632(%rip), %rsi     # 0x35d11
movl $0x34, %edx
movq %r14, %rdi
callq 0x53a0
leaq 0x1e4a2(%rip), %rsi     # 0x35b95
movl $0x1c, %edx
movq %r14, %rdi
callq 0x53a0
leaq 0x1e63f(%rip), %rsi     # 0x35d46
movl $0x6, %edx
movq %r14, %rdi
callq 0x53a0
movl $0x1c2, %esi            # imm = 0x1C2
movq %r14, %rdi
callq 0x5620
leaq 0x1cf4e(%rip), %rsi     # 0x34676
movl $0x2, %edx
movq %rax, %rdi
movq %rax, %r14
callq 0x53a0
leaq 0x88(%rsp), %r15
movl $0x1, %edx
movq %rbx, %rsi
movq %r15, %rdi
callq 0x20794
leaq 0x1c1b9(%rip), %rsi     # 0x33910
leaq 0x68(%rsp), %rdi
movq %r15, %rdx
callq 0x17dad
leaq 0x1c1a5(%rip), %rsi     # 0x33910
leaq 0x68(%rsp), %rdi
callq 0x56e0
leaq 0x38(%rsp), %r15
movq %rax, %rcx
addq $0x10, %rcx
movq %r15, -0x10(%r15)
movq (%rax), %rdx
cmpq %rcx, %rdx
jne 0x17798
vmovups (%rcx), %xmm0
vmovups %xmm0, (%r15)
jmp 0x177a5
movq %rdx, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
movq 0x8(%rax), %rdx
movq %rdx, 0x30(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x48(%rsp), %rdi
leaq 0x6(%rsp), %rsi
callq 0x10fbe
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x17cae
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x53a0
movq %rax, %rdi
callq 0x5160
leaq 0x8(%rsp), %rdi
callq 0x5150
leaq 0x48(%rsp), %rdi
callq 0x5150
leaq 0x28(%rsp), %rdi
callq 0x5150
leaq 0x68(%rsp), %rdi
callq 0x5150
leaq 0x88(%rsp), %rdi
callq 0x5150
movl $0x1, %edi
callq 0x5420
leaq 0x18(%rsp), %rcx
movq %rax, %rbx
movq -0x10(%rcx), %rdi
cmpq %rcx, %rdi
je 0x17854
callq 0x52e0
jmp 0x17854
movq %rax, %rbx
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1786c
callq 0x52e0
jmp 0x1786c
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x17880
callq 0x52e0
jmp 0x17880
movq %rax, %rbx
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x17898
callq 0x52e0
jmp 0x17898
movq %rax, %rbx
leaq 0x98(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x178ae
callq 0x52e0
movq %rbx, %rdi
callq 0x5670