// File: tewalds[P]morat/hex/agentmctsthread.cpp
// Function: Morat::Hex::AgentMCTS::AgentThread::rollout(Morat::Hex::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);

	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 0xff40
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0xd8(%rax)
je 0x2819b
movq 0x30(%rsp), %rax
movq %rax, %rdi
addq $0x2f08, %rdi           # imm = 0x2F08
movq 0x100(%rsp), %rsi
movq 0x40(%rax), %rax
movl 0xd8(%rax), %edx
callq 0x29ca0
movq 0x30(%rsp), %rdi
addq $0xa14, %rdi            # imm = 0xA14
movq 0x100(%rsp), %rsi
callq 0x29d10
movq 0x100(%rsp), %rdi
callq 0x1a900
movb %al, 0xfb(%rsp)
movb 0xfb(%rsp), %al
movb %al, 0x117(%rsp)
leaq 0x117(%rsp), %rdi
leaq 0x452de(%rip), %rsi     # 0x6d4c3
callq 0x1b520
testb $0x1, %al
jne 0x281f3
jmp 0x2847a
movq 0x100(%rsp), %rdi
callq 0x1a8a0
movq 0x30(%rsp), %rdi
movb %al, 0xfa(%rsp)
movq 0x100(%rsp), %rsi
leaq 0x115(%rsp), %rdx
callq 0x28b70
movq 0x30(%rsp), %rdi
movw %ax, 0xf8(%rsp)
movw 0xf8(%rsp), %ax
movw %ax, 0x115(%rsp)
addq $0xcb78, %rdi           # imm = 0xCB78
movb 0xfa(%rsp), %al
movb %al, 0xf7(%rsp)
leaq 0x115(%rsp), %rsi
movzbl 0xf7(%rsp), %edx
callq 0x29d30
movq 0x100(%rsp), %rdi
leaq 0x115(%rsp), %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x1c500
testb $0x1, %al
jne 0x28462
movq 0x44d5d(%rip), %rdi     # 0x6cff0
leaq 0x263c3(%rip), %rsi     # 0x4e65d
callq 0x53e0
movq %rax, %rdi
leaq 0x2624c(%rip), %rsi     # 0x4e4f5
callq 0x53e0
movq %rax, %rdi
leaq 0x263da(%rip), %rsi     # 0x4e692
callq 0x53e0
movq %rax, %rdi
movl $0x1ad, %esi            # imm = 0x1AD
callq 0x5730
movq %rax, %rdi
leaq 0x25062(%rip), %rsi     # 0x4d336
callq 0x53e0
movq %rax, 0x20(%rsp)
movq 0x100(%rsp), %rsi
leaq 0x70(%rsp), %rdi
movq %rdi, 0x28(%rsp)
movl $0x1, %edx
callq 0x35f30
movq 0x28(%rsp), %rdx
leaq 0x245e2(%rip), %rsi     # 0x4c8e8
leaq 0x90(%rsp), %rdi
callq 0x19f30
jmp 0x28315
leaq 0x245cc(%rip), %rdx     # 0x4c8e8
leaq 0xb0(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0xb910
jmp 0x28333
leaq 0x40(%rsp), %rdi
leaq 0x115(%rsp), %rsi
callq 0x19f80
jmp 0x28347
leaq 0xd0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x19e40
jmp 0x28363
movq 0x20(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x5370
movq %rax, 0x18(%rsp)
jmp 0x2837c
movq 0x18(%rsp), %rdi
movq 0x44c20(%rip), %rsi     # 0x6cfa8
callq 0x5420
jmp 0x2838f
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 0x28453
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
jmp 0x28446
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
jmp 0x28439
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
jmp 0x2842f
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 0x28581
jmp 0x28464
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
jmp 0x281b4
movq 0x30(%rsp), %rdi
addq $0x12148, %rdi          # imm = 0x12148
movl 0xfc(%rsp), %esi
callq 0x29180
leaq 0x117(%rsp), %rdi
leaq 0x45022(%rip), %rsi     # 0x6d4c3
callq 0x29db0
testb $0x1, %al
jne 0x284ac
jmp 0x2850f
movq 0x30(%rsp), %rax
addq $0x12168, %rax          # imm = 0x12168
movq %rax, 0x8(%rsp)
leaq 0x117(%rsp), %rdi
callq 0x1a4c0
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 0x29df0
movq 0x10(%rsp), %rdi
movsbl %al, %eax
cltq
shlq $0x5, %rax
addq %rax, %rdi
movl 0xfc(%rsp), %esi
callq 0x29180
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0xd4(%rax)
je 0x28551
movq 0x30(%rsp), %rdx
movq %rdx, %rdi
addq $0x4c, %rdi
movq 0x100(%rsp), %rsi
addq $0xcb78, %rdx           # imm = 0xCB78
movb 0x117(%rsp), %al
movb %al, 0x3f(%rsp)
movzbl 0x3f(%rsp), %ecx
callq 0x29e00
movq 0x30(%rsp), %rdi
addq $0xcb78, %rdi           # imm = 0xCB78
movb 0x117(%rsp), %al
movb %al, 0x3e(%rsp)
movzbl 0x3e(%rsp), %esi
callq 0x28ff0
movb 0x117(%rsp), %al
addq $0x118, %rsp            # imm = 0x118
retq
movq 0x68(%rsp), %rdi
callq 0x5760
nopl (%rax,%rax)