// File: /workspace/github_cpp_makefile_star2_O2/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, 0x2(%rsp)
movl %ecx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
movq 0x40(%rdi), %rax
movl 0x13c(%rax), %ecx
testl %ecx, %ecx
je 0x12472
movsbl (%rbx), %edx
imull %ecx, %edx
negl %edx
testl %ecx, %ecx
cmovnsl %ecx, %edx
movl %edx, 0x28d8(%r14)
andl $0x0, 0x28dc(%r14)
movw $0x78fc, 0x28e0(%r14)   # imm = 0x78FC
movl 0x8cc(%r14), %ecx
vxorps %xmm1, %xmm1, %xmm1
movl %ecx, 0x8d0(%r14)
vmovss 0x12c(%rax), %xmm0
vucomiss %xmm0, %xmm1
jbe 0x124cd
leaq 0x17570(%rip), %rdx     # 0x29a09
movb 0xb(%rbx), %cl
movswl 0x6(%rbx), %esi
cmpb (%rdx), %cl
movswl 0x4(%rbx), %edx
setl %cl
subl %esi, %edx
vcvtsi2ss %edx, %xmm2, %xmm1
kmovd %ecx, %k1
vmovss %xmm1, %xmm1, %xmm1 {%k1} {z}
vxorps 0x14299(%rip){1to4}, %xmm0, %xmm0 # 0x2675c
vmulss %xmm0, %xmm1, %xmm0
vroundss $0xa, %xmm0, %xmm0, %xmm0
movl 0x130(%rax), %eax
vcvttss2si %xmm0, %ecx
leaq 0x12158(%r14), %r13
leaq 0x2(%rsp), %r12
movl %ecx, 0x4(%rsp)
movl %eax, 0x9c(%rbx)
movsbq 0xb(%rbx), %r15
leaq 0x17510(%rip), %rax     # 0x29a09
cmpb (%rax), %r15b
jge 0x12566
cmpl 0x4(%rsp), %ebp
movb 0xa(%rbx), %r15b
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
setl 0x98(%rbx)
callq 0x12a1c
movw %ax, 0x2(%rsp)
movq %rbx, %rdi
movslq 0x12598(%r14), %rdx
movslq 0x12594(%r14), %rcx
addq %rdx, %rcx
leal 0x1(%rdx), %esi
leaq (%rcx,%rcx,2), %rcx
movl %esi, 0x12598(%r14)
movq %r12, %rsi
movw %ax, (%r13,%rcx)
movb %r15b, 0x2(%r13,%rcx)
pushq $0x1
popq %rdx
xorl %ecx, %ecx
callq 0xe40c
testb %al, %al
je 0x125e9
incl %ebp
jmp 0x124ed
leaq 0x125d0(%r14), %rdi
movl %ebp, %esi
callq 0x12c24
leaq 0x1748e(%rip), %rax     # 0x29a09
cmpb (%rax), %r15b
jle 0x1259f
movsbq 0xc(%rbx), %rax
imulq $0x60, %r15, %rcx
movl %ebp, %esi
addq %r14, %rcx
shlq $0x5, %rax
leaq 0x12590(%rax,%rcx), %rdi
callq 0x12c24
movq 0x40(%r14), %rax
cmpl $0x0, 0x138(%rax)
je 0x125c2
leaq 0x4c(%r14), %rdi
leaq 0xf418(%r14), %rdx
movq %rbx, %rsi
movl %r15d, %ecx
callq 0x1315e
addq $0xf418, %r14           # imm = 0xF418
movl %r15d, %esi
movq %r14, %rdi
callq 0x12b78
movl %r15d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2ca00(%rip), %rdi     # 0x3eff0
leaq 0x1430a(%rip), %rsi     # 0x26901
callq 0x5320
leaq 0x14182(%rip), %rsi     # 0x26785
movq %rax, %rdi
callq 0x5320
leaq 0x14324(%rip), %rsi     # 0x26936
movq %rax, %rdi
callq 0x5320
movl $0x1c2, %esi            # imm = 0x1C2
movq %rax, %rdi
callq 0x5610
leaq 0x12e8d(%rip), %rsi     # 0x254bb
movq %rax, %rdi
callq 0x5320
movq %rax, %r14
leaq 0x88(%rsp), %r15
pushq $0x1
popq %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x18a86
leaq 0x122a8(%rip), %rsi     # 0x248fe
leaq 0x28(%rsp), %rdi
movq %r15, %rdx
callq 0xd17f
leaq 0x12294(%rip), %rdx     # 0x248fe
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x8061
leaq 0x8(%rsp), %rdi
leaq 0x2(%rsp), %rsi
callq 0xd1a4
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0xd118
leaq 0x68(%rsp), %rsi
movq %r14, %rdi
callq 0x52c0
movq %rax, %rdi
callq 0x5170
leaq 0x68(%rsp), %rdi
callq 0x5150
leaq 0x8(%rsp), %rdi
callq 0x5150
leaq 0x48(%rsp), %rdi
callq 0x5150
leaq 0x28(%rsp), %rdi
callq 0x5150
leaq 0x88(%rsp), %rdi
callq 0x5150
pushq $0x1
popq %rdi
callq 0x5430
leaq 0x68(%rsp), %rdi
movq %rax, %rbx
callq 0x5150
jmp 0x12700
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x5150
jmp 0x1270f
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x5150
jmp 0x1271e
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x5150
jmp 0x1272d
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x5150
movq %rbx, %rdi
callq 0x5650