// File: 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:
subq $0x118, %rsp            # imm = 0x118
movw %dx, %ax
movw %ax, 0x115(%rsp)
movq %rdi, 0x108(%rsp)
movq %rsi, 0x100(%rsp)
movl %ecx, 0xfc(%rsp)
movq 0x108(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x117(%rsp), %rdi
callq 0xff60
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0x13c(%rax)
je 0x2899b
movq 0x30(%rsp), %rax
movq %rax, %rdi
addq $0x28d8, %rdi           # imm = 0x28D8
movq 0x100(%rsp), %rsi
movq 0x40(%rax), %rax
movl 0x13c(%rax), %edx
callq 0x2a860
movq 0x30(%rsp), %rdi
addq $0x5f4, %rdi            # imm = 0x5F4
movq 0x100(%rsp), %rsi
callq 0x2a8d0
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rcx
vcvttss2si 0x12c(%rcx), %ecx
movl %ecx, 0xf8(%rsp)
movq 0x40(%rax), %rax
vpxor %xmm0, %xmm0, %xmm0
vucomiss 0x12c(%rax), %xmm0
jbe 0x28a23
movq 0x100(%rsp), %rdi
callq 0x297b0
movl %eax, %ecx
movq 0x30(%rsp), %rax
vcvtsi2ss %ecx, %xmm0, %xmm0
movq 0x40(%rax), %rax
vmulss 0x12c(%rax), %xmm0, %xmm0
vmovss 0x26832(%rip), %xmm1    # 0x4f23c
vmulss %xmm1, %xmm0, %xmm1
vcvtss2sd %xmm1, %xmm0, %xmm1
vroundsd $0xa, %xmm1, %xmm0, %xmm0
vcvttsd2si %xmm0, %eax
movl %eax, 0xf8(%rsp)
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rax
movl 0x130(%rax), %ecx
movq 0x100(%rsp), %rax
movl %ecx, 0x9c(%rax)
movq 0x100(%rsp), %rdi
callq 0x1aaa0
movb %al, 0xf7(%rsp)
movb 0xf7(%rsp), %al
movb %al, 0x117(%rsp)
leaq 0x117(%rsp), %rdi
leaq 0x46a72(%rip), %rsi     # 0x6f4e3
callq 0x1b6c0
testb $0x1, %al
jne 0x28a7f
jmp 0x28d28
movq 0x100(%rsp), %rdi
callq 0x1aa40
movq 0x30(%rsp), %rdi
movb %al, 0xf6(%rsp)
movl 0xfc(%rsp), %eax
cmpl 0xf8(%rsp), %eax
setl %cl
movq 0x100(%rsp), %rax
andb $0x1, %cl
movb %cl, 0x98(%rax)
movq 0x100(%rsp), %rsi
leaq 0x115(%rsp), %rdx
callq 0x294a0
movq 0x30(%rsp), %rdi
movw %ax, 0xf4(%rsp)
movw 0xf4(%rsp), %ax
movw %ax, 0x115(%rsp)
addq $0xf418, %rdi           # imm = 0xF418
movb 0xf6(%rsp), %al
movb %al, 0xf3(%rsp)
leaq 0x115(%rsp), %rsi
movzbl 0xf3(%rsp), %edx
callq 0x2a8f0
movq 0x100(%rsp), %rdi
leaq 0x115(%rsp), %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x1c6d0
testb $0x1, %al
jne 0x28d10
movq 0x464af(%rip), %rdi     # 0x6eff0
leaq 0x27d45(%rip), %rsi     # 0x5088d
callq 0x53f0
movq %rax, %rdi
leaq 0x27bba(%rip), %rsi     # 0x50711
callq 0x53f0
movq %rax, %rdi
leaq 0x27d5c(%rip), %rsi     # 0x508c2
callq 0x53f0
movq %rax, %rdi
movl $0x1c2, %esi            # imm = 0x1C2
callq 0x5740
movq %rax, %rdi
leaq 0x268d9(%rip), %rsi     # 0x4f45b
callq 0x53f0
movq %rax, 0x20(%rsp)
movq 0x100(%rsp), %rsi
leaq 0x70(%rsp), %rdi
movq %rdi, 0x28(%rsp)
movl $0x1, %edx
callq 0x37430
movq 0x28(%rsp), %rdx
leaq 0x25d3e(%rip), %rsi     # 0x4e8f2
leaq 0x90(%rsp), %rdi
callq 0x1a0d0
jmp 0x28bc3
leaq 0x25d28(%rip), %rdx     # 0x4e8f2
leaq 0xb0(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0xb920
jmp 0x28be1
leaq 0x40(%rsp), %rdi
leaq 0x115(%rsp), %rsi
callq 0x1a120
jmp 0x28bf5
leaq 0xd0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x19fe0
jmp 0x28c11
movq 0x20(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x5380
movq %rax, 0x18(%rsp)
jmp 0x28c2a
movq 0x18(%rsp), %rdi
movq 0x46372(%rip), %rsi     # 0x6efa8
callq 0x5430
jmp 0x28c3d
leaq 0xd0(%rsp), %rdi
callq 0x5260
leaq 0x40(%rsp), %rdi
callq 0x5260
leaq 0xb0(%rsp), %rdi
callq 0x5260
leaq 0x90(%rsp), %rdi
callq 0x5260
leaq 0x70(%rsp), %rdi
callq 0x5260
movl $0x1, %edi
callq 0x5500
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
jmp 0x28d01
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
jmp 0x28cf4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
jmp 0x28ce7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
jmp 0x28cdd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x5260
leaq 0x40(%rsp), %rdi
callq 0x5260
leaq 0xb0(%rsp), %rdi
callq 0x5260
leaq 0x90(%rsp), %rdi
callq 0x5260
leaq 0x70(%rsp), %rdi
callq 0x5260
jmp 0x28e2f
jmp 0x28d12
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
jmp 0x28a40
movq 0x30(%rsp), %rdi
addq $0x125d0, %rdi          # imm = 0x125D0
movl 0xfc(%rsp), %esi
callq 0x29ab0
leaq 0x117(%rsp), %rdi
leaq 0x46794(%rip), %rsi     # 0x6f4e3
callq 0x2a970
testb $0x1, %al
jne 0x28d5a
jmp 0x28dbd
movq 0x30(%rsp), %rax
addq $0x125f0, %rax          # imm = 0x125F0
movq %rax, 0x8(%rsp)
leaq 0x117(%rsp), %rdi
callq 0x1a660
movb %al, %cl
movq 0x8(%rsp), %rax
movsbl %cl, %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x100(%rsp), %rdi
callq 0x2a9b0
movq 0x10(%rsp), %rdi
movsbl %al, %eax
cltq
shlq $0x5, %rax
addq %rax, %rdi
movl 0xfc(%rsp), %esi
callq 0x29ab0
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0x138(%rax)
je 0x28dff
movq 0x30(%rsp), %rdx
movq %rdx, %rdi
addq $0x4c, %rdi
movq 0x100(%rsp), %rsi
addq $0xf418, %rdx           # imm = 0xF418
movb 0x117(%rsp), %al
movb %al, 0x3f(%rsp)
movzbl 0x3f(%rsp), %ecx
callq 0x2a9c0
movq 0x30(%rsp), %rdi
addq $0xf418, %rdi           # imm = 0xF418
movb 0x117(%rsp), %al
movb %al, 0x3e(%rsp)
movzbl 0x3e(%rsp), %esi
callq 0x29920
movb 0x117(%rsp), %al
addq $0x118, %rsp            # imm = 0x118
retq
movq 0x68(%rsp), %rdi
callq 0x5770
nopl (%rax)