// File: tyhsu[P]Ewn/mcts.cpp
// Function: MCTS::simulation(Game const&)
int MCTS::simulation(const Game& cur_game) {
    Game simu_game = cur_game;
	char cur_symbol;
	int game_status = 0, ai_win = this->ai_side ? 2 : 1;
	if (simu_game.get_is_switch() == this->ai_side)
		cur_symbol = this->ai_symbol;
	else
		cur_symbol = this->ai_side? '1' : 'A';

	while (game_status == 0) {
		Movement available_mvmt_list[18];
		int available_mvmt_cnt = 0;
		// find all avaible move (6 dice indices, 3 directions)
		for(int chs_index = 0; chs_index < 6; chs_index++) {
			Chess cur_chs = simu_game.get_cur_chs_list(chs_index);
			if (cur_chs.exist) {
				for (int direct = 0; direct < 3; direct++) {
					Movement tmp_mvmt(chs_index, direct);
					if (simu_game.check_in_board(tmp_mvmt)) {
						available_mvmt_list[available_mvmt_cnt] = tmp_mvmt;
						available_mvmt_cnt ++;
					}
				}
			}
		}
		// randomly pick a move.
		Movement next_mvmt = available_mvmt_list[rand() % available_mvmt_cnt];
		game_status = simu_game.update_game_status(next_mvmt);

		// check game status => if the game keep going, switch the player.
		if(game_status == 0) simu_game.switch_player();
		else break;
	}
	return (game_status == ai_win? 1: 0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1e8(%rbp)
movq -0x10(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
callq 0xa520
movq -0x1e8(%rbp), %rax
movl $0x0, -0x100(%rbp)
movb (%rax), %dl
movl $0x1, %eax
movl $0x2, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x104(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0xb910
movq -0x1e8(%rbp), %rcx
andb $0x1, %al
movzbl %al, %eax
movb (%rcx), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x6f2d
movq -0x1e8(%rbp), %rax
movb 0x1(%rax), %al
movb %al, -0xf9(%rbp)
jmp 0x6f63
movq -0x1e8(%rbp), %rax
movb (%rax), %cl
movb $0x31, %al
movb $0x41, %dl
movb %dl, -0x1ea(%rbp)
testb $0x1, %cl
movb %al, -0x1e9(%rbp)
jne 0x6f57
movb -0x1ea(%rbp), %al
movb %al, -0x1e9(%rbp)
movb -0x1e9(%rbp), %al
movb %al, -0xf9(%rbp)
jmp 0x6f65
cmpl $0x0, -0x100(%rbp)
jne 0x7120
leaq -0x1a0(%rbp), %rax
movq %rax, %rcx
addq $0x90, %rcx
movq %rcx, -0x200(%rbp)
movq %rax, -0x1f8(%rbp)
movq -0x1f8(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x4c60
movq -0x208(%rbp), %rax
movq -0x200(%rbp), %rcx
addq $0x8, %rax
cmpq %rcx, %rax
movq %rax, -0x1f8(%rbp)
jne 0x6f91
movl $0x0, -0x1a4(%rbp)
movl $0x0, -0x1a8(%rbp)
cmpl $0x6, -0x1a8(%rbp)
jge 0x70cb
leaq -0xf8(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0xb810
movl %edx, -0x1c0(%rbp)
movq %rax, -0x1c8(%rbp)
movq -0x1c8(%rbp), %rax
movq %rax, -0x1b4(%rbp)
movl -0x1c0(%rbp), %eax
movl %eax, -0x1ac(%rbp)
testb $0x1, -0x1b3(%rbp)
je 0x70b5
movl $0x0, -0x1cc(%rbp)
cmpl $0x3, -0x1cc(%rbp)
jge 0x70b3
leaq -0x1d4(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
leaq -0x1cc(%rbp), %rdx
callq 0x5c40
leaq -0xf8(%rbp), %rdi
leaq -0x1d4(%rbp), %rsi
callq 0xafe0
testb $0x1, %al
jne 0x7070
jmp 0x70a0
movslq -0x1a4(%rbp), %rax
leaq -0x1a0(%rbp), %rdi
shlq $0x3, %rax
addq %rax, %rdi
leaq -0x1d4(%rbp), %rsi
callq 0x6a30
movl -0x1a4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1a4(%rbp)
jmp 0x70a2
movl -0x1cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1cc(%rbp)
jmp 0x7034
jmp 0x70b5
jmp 0x70b7
movl -0x1a8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1a8(%rbp)
jmp 0x6fd6
callq 0x2050
cltd
idivl -0x1a4(%rbp)
movslq %edx, %rax
movq -0x1a0(%rbp,%rax,8), %rax
movq %rax, -0x1dc(%rbp)
leaq -0xf8(%rbp), %rdi
leaq -0x1dc(%rbp), %rsi
callq 0xb120
movl %eax, -0x100(%rbp)
cmpl $0x0, -0x100(%rbp)
jne 0x7119
leaq -0xf8(%rbp), %rdi
callq 0xb440
jmp 0x711b
jmp 0x7120
jmp 0x6f65
movl -0x100(%rbp), %edx
movl -0x104(%rbp), %esi
xorl %eax, %eax
movl $0x1, %ecx
cmpl %esi, %edx
cmovel %ecx, %eax
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
nopw %cs:(%rax,%rax)