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

	random_policy.rollout_start(board);

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

		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 0xfe10
movq 0x30(%rsp), %rdi
addq $0xa14, %rdi            # imm = 0xA14
movq 0x100(%rsp), %rsi
callq 0x28b70
movq 0x100(%rsp), %rdi
callq 0x1a700
movb %al, 0xfb(%rsp)
movb 0xfb(%rsp), %al
movb %al, 0x117(%rsp)
leaq 0x117(%rsp), %rdi
leaq 0x3e8ce(%rip), %rsi     # 0x664db
callq 0x1b320
testb $0x1, %al
jne 0x27c1b
jmp 0x27ea2
movq 0x100(%rsp), %rdi
callq 0x1a6a0
movq 0x30(%rsp), %rdi
movb %al, 0xfa(%rsp)
movq 0x100(%rsp), %rsi
leaq 0x115(%rsp), %rdx
callq 0x28200
movq 0x30(%rsp), %rdi
movw %ax, 0xf8(%rsp)
movw 0xf8(%rsp), %ax
movw %ax, 0x115(%rsp)
addq $0xf08, %rdi            # imm = 0xF08
movb 0xfa(%rsp), %al
movb %al, 0xf7(%rsp)
leaq 0x115(%rsp), %rsi
movzbl 0xf7(%rsp), %edx
callq 0x28b90
movq 0x100(%rsp), %rdi
leaq 0x115(%rsp), %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x1c300
testb $0x1, %al
jne 0x27e8a
movq 0x3e335(%rip), %rdi     # 0x65ff0
leaq 0x21a1b(%rip), %rsi     # 0x496dd
callq 0x53e0
movq %rax, %rdi
leaq 0x21898(%rip), %rsi     # 0x49569
callq 0x53e0
movq %rax, %rdi
leaq 0x21a32(%rip), %rsi     # 0x49712
callq 0x53e0
movq %rax, %rdi
movl $0x168, %esi            # imm = 0x168
callq 0x5730
movq %rax, %rdi
leaq 0x20619(%rip), %rsi     # 0x48315
callq 0x53e0
movq %rax, 0x20(%rsp)
movq 0x100(%rsp), %rsi
leaq 0x70(%rsp), %rdi
movq %rdi, 0x28(%rsp)
movl $0x1, %edx
callq 0x33510
movq 0x28(%rsp), %rdx
leaq 0x1fb89(%rip), %rsi     # 0x478b7
leaq 0x90(%rsp), %rdi
callq 0x19d30
jmp 0x27d3d
leaq 0x1fb73(%rip), %rdx     # 0x478b7
leaq 0xb0(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0xb7e0
jmp 0x27d5b
leaq 0x40(%rsp), %rdi
leaq 0x115(%rsp), %rsi
callq 0x19d80
jmp 0x27d6f
leaq 0xd0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x19c40
jmp 0x27d8b
movq 0x20(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x5370
movq %rax, 0x18(%rsp)
jmp 0x27da4
movq 0x18(%rsp), %rdi
movq 0x3e1f8(%rip), %rsi     # 0x65fa8
callq 0x5420
jmp 0x27db7
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 0x54f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
jmp 0x27e7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
jmp 0x27e6e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
jmp 0x27e61
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
jmp 0x27e57
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 0x27fa9
jmp 0x27e8c
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
jmp 0x27bdc
movq 0x30(%rsp), %rdi
addq $0x64d8, %rdi           # imm = 0x64D8
movl 0xfc(%rsp), %esi
callq 0x28770
leaq 0x117(%rsp), %rdi
leaq 0x3e612(%rip), %rsi     # 0x664db
callq 0x28c10
testb $0x1, %al
jne 0x27ed4
jmp 0x27f37
movq 0x30(%rsp), %rax
addq $0x64f8, %rax           # imm = 0x64F8
movq %rax, 0x8(%rsp)
leaq 0x117(%rsp), %rdi
callq 0x1a2c0
movb %al, %cl
movq 0x8(%rsp), %rax
movsbl %cl, %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x100(%rsp), %rdi
callq 0x28c50
movq 0x10(%rsp), %rdi
movsbl %al, %eax
cltq
shlq $0x5, %rax
addq %rax, %rdi
movl 0xfc(%rsp), %esi
callq 0x28770
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0xb8(%rax)
je 0x27f79
movq 0x30(%rsp), %rdx
movq %rdx, %rdi
addq $0x4c, %rdi
movq 0x100(%rsp), %rsi
addq $0xf08, %rdx            # imm = 0xF08
movb 0x117(%rsp), %al
movb %al, 0x3f(%rsp)
movzbl 0x3f(%rsp), %ecx
callq 0x28c60
movq 0x30(%rsp), %rdi
addq $0xf08, %rdi            # imm = 0xF08
movb 0x117(%rsp), %al
movb %al, 0x3e(%rsp)
movzbl 0x3e(%rsp), %esi
callq 0x285e0
movb 0x117(%rsp), %al
addq $0x118, %rsp            # imm = 0x118
retq
movq 0x68(%rsp), %rdi
callq 0x5760
nopw %cs:(%rax,%rax)