// File: /workspace/github_cpp_makefile_star2_O1/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
movl %ecx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
movw %dx, 0x6(%rsp)
movq 0x40(%rdi), %rax
movl 0x13c(%rax), %ecx
testl %ecx, %ecx
je 0x1765d
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
movl %ecx, 0x8d0(%r14)
vmovss 0x12c(%rax), %xmm0
vxorps %xmm1, %xmm1, %xmm1
vucomiss %xmm0, %xmm1
jbe 0x176b8
movb 0xb(%rbx), %cl
leaq 0x21a82(%rip), %rdx     # 0x39109
cmpb (%rdx), %cl
setl %cl
movswl 0x4(%rbx), %edx
movswl 0x6(%rbx), %esi
subl %esi, %edx
vcvtsi2ss %edx, %xmm2, %xmm1
kmovd %ecx, %k1
vmovss %xmm1, %xmm1, %xmm1 {%k1} {z}
vxorps 0x1e272(%rip){1to4}, %xmm0, %xmm0 # 0x35920
vmulss %xmm0, %xmm1, %xmm0
vroundss $0xa, %xmm0, %xmm0, %xmm0
movl 0x130(%rax), %eax
movl %eax, 0x9c(%rbx)
movb 0xb(%rbx), %r15b
leaq 0x21a3a(%rip), %rax     # 0x39109
cmpb (%rax), %r15b
jge 0x17783
vcvttss2si %xmm0, %r12d
leaq 0x12158(%r14), %r13
movb 0xa(%rbx), %r15b
cmpl %r12d, %ebp
setl 0x98(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x6(%rsp), %rdx
callq 0x17d92
movw %ax, 0x6(%rsp)
movslq 0x12594(%r14), %rcx
movslq 0x12598(%r14), %rdx
leal 0x1(%rdx), %esi
movl %esi, 0x12598(%r14)
addq %rdx, %rcx
leaq (%rcx,%rcx,2), %rcx
movw %ax, (%r13,%rcx)
movb %r15b, 0x2(%r13,%rcx)
movsbl 0x6(%rsp), %eax
movsbl (%rbx), %ecx
imull %eax, %ecx
movsbl 0x7(%rsp), %eax
addl %ecx, %eax
movzwl 0x6(%rsp), %ecx
movw %cx, 0x8(%rsp)
movw %ax, 0xa(%rsp)
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x13aea
testb %al, %al
je 0x17810
incl %ebp
movb 0xb(%rbx), %r15b
leaq 0x2198f(%rip), %rax     # 0x39109
cmpb (%rax), %r15b
jl 0x176e3
leaq 0x125d0(%r14), %rdi
movl %ebp, %esi
callq 0x180c2
leaq 0x21971(%rip), %rax     # 0x39109
cmpb (%rax), %r15b
jle 0x177c4
movsbq %r15b, %rax
movsbq 0xc(%rbx), %rcx
shlq $0x5, %rcx
leaq (%rax,%rax,2), %rax
shlq $0x5, %rax
addq %r14, %rax
leaq 0x12590(%rcx,%rax), %rdi
movl %ebp, %esi
callq 0x180c2
movq 0x40(%r14), %rax
cmpl $0x0, 0x138(%rax)
movzbl %r15b, %ebp
je 0x177ea
leaq 0x4c(%r14), %rdi
leaq 0xf418(%r14), %rdx
movq %rbx, %rsi
movl %ebp, %ecx
callq 0x1867a
addq $0xf418, %r14           # imm = 0xF418
movq %r14, %rdi
movl %ebp, %esi
callq 0x18004
movl %r15d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x357d9(%rip), %r14     # 0x4cff0
leaq 0x1e4f3(%rip), %rsi     # 0x35d11
movl $0x34, %edx
movq %r14, %rdi
callq 0x53a0
leaq 0x1e363(%rip), %rsi     # 0x35b95
movl $0x1c, %edx
movq %r14, %rdi
callq 0x53a0
leaq 0x1e500(%rip), %rsi     # 0x35d46
movl $0x6, %edx
movq %r14, %rdi
callq 0x53a0
movq %r14, %rdi
movl $0x1c2, %esi            # imm = 0x1C2
callq 0x5620
movq %rax, %r14
leaq 0x1ce0c(%rip), %rsi     # 0x34676
movl $0x2, %edx
movq %rax, %rdi
callq 0x53a0
leaq 0x88(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x20a0e
leaq 0x1c07a(%rip), %rsi     # 0x33910
leaq 0x68(%rsp), %rdi
movq %r15, %rdx
callq 0x17f25
leaq 0x1c066(%rip), %rsi     # 0x33910
leaq 0x68(%rsp), %rdi
callq 0x56e0
leaq 0x38(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
jne 0x178d7
vmovups (%rcx), %xmm0
vmovups %xmm0, (%r15)
jmp 0x178e4
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 0x10fe8
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x17e26
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
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
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x17993
callq 0x52e0
jmp 0x17993
movq %rax, %rbx
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x179ab
callq 0x52e0
jmp 0x179ab
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x179bf
callq 0x52e0
jmp 0x179bf
movq %rax, %rbx
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x179d7
callq 0x52e0
jmp 0x179d7
movq %rax, %rbx
leaq 0x98(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x179ed
callq 0x52e0
movq %rbx, %rdi
callq 0x5670