// File: /workspace/github_cpp_makefile_star2_O3/tyhsu[P]Ewn/game.cpp
// Function: Game::update_game_status(std::pair<int, int> const&)
int Game::update_game_status(const Movement& mvmt)
{
	Chess next_chs = this->cur_chs_list_ptr[mvmt.first];
	int direct = mvmt.second;
	int side = (this->is_switch == false)? 1 : -1;
	char eaten_chs_symbol;

	// Clear previous location
	Chess blank_chs = next_chs;
	blank_chs.symbol = 0;
	this->set_chs_on_board(blank_chs);
	// Update the chosen movement on the board
	int chs_list_index = 0;
	if (!this->is_switch)	//chs_list_A
		chs_list_index = next_chs.symbol - '1';
	else				//chs_list_B
		chs_list_index = next_chs.symbol - 'A';

	if (direct == 0)		// move right
		this->cur_chs_list_ptr[chs_list_index].move_x_one_unit(side);
	else if (direct == 1)	// move down
		this->cur_chs_list_ptr[chs_list_index].move_y_one_unit(side);
	else if (direct == 2)	// move right down
		this->cur_chs_list_ptr[chs_list_index].move_x_one_unit(side),
		this->cur_chs_list_ptr[chs_list_index].move_y_one_unit(side);

	Chess chs = this->cur_chs_list_ptr[chs_list_index];
	eaten_chs_symbol = this->get_symbol_on_board(chs.x, chs.y);
	this->set_chs_on_board(chs);

	// Update the eaten chessman
	if (eaten_chs_symbol != 0) {
		// should delete a single piece.
		if (eaten_chs_symbol < 'A') {
			// this Play is A
			this->chs_list_A[eaten_chs_symbol-'1'].exist = false;
			this->exist_bitwise_A -= 1 << int(eaten_chs_symbol-'1');
			this->exist_chs_num_A--;
		}
		else {
			// this Play is B
			this->chs_list_B[eaten_chs_symbol-'A'].exist = false;
			this->exist_bitwise_B -= 1 << int(eaten_chs_symbol-'A');
			this->exist_chs_num_B--;
		}
	}

	// Check if any player arrives the end-game position
	for (int i = 0; i < 6; i++) {
		if(this->chs_list_A[i].x == 4 && this->chs_list_A[i].y == 4)
			return 1;
		if(this->chs_list_B[i].x == 0 && this->chs_list_B[i].y == 0)
			return 2;
	}

	// Check if the other player is killed the game.
	if (!this->is_switch && this->exist_chs_num_B==0)		//this player is A
		return 1;
	else if (this->is_switch && this->exist_chs_num_A==0)	//this player is B
		return 2;

	//The game has not come to a close
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq 0xd0(%rdi), %rax
movslq (%rsi), %rcx
leaq (%rcx,%rcx,2), %rcx
movsbq (%rax,%rcx,4), %rdx
movslq 0x4(%rax,%rcx,4), %r8
movslq 0x8(%rax,%rcx,4), %rcx
movl 0x4(%rsi), %esi
movzbl 0xe4(%rdi), %eax
negl %eax
orl $0x1, %eax
leaq (%r8,%r8,4), %r8
addq %rdi, %r8
movb $0x0, (%rcx,%r8)
movzbl 0xe4(%rdi), %ecx
xorl $0x1, %ecx
shll $0x4, %ecx
addq %rcx, %rdx
addq $-0x41, %rdx
movq 0xd0(%rdi), %rcx
cmpl $0x2, %esi
je 0x806b
cmpl $0x1, %esi
je 0x805d
testl %esi, %esi
jne 0x807c
leaq (%rdx,%rdx,2), %rsi
leaq (%rcx,%rsi,4), %rsi
addq $0x4, %rsi
jmp 0x807a
leaq (%rdx,%rdx,2), %rsi
leaq (%rcx,%rsi,4), %rsi
addq $0x8, %rsi
jmp 0x807a
leaq (%rdx,%rdx,2), %rsi
leaq (%rcx,%rsi,4), %rsi
addq $0x8, %rsi
addl %eax, -0x4(%rsi)
addl %eax, (%rsi)
leaq (%rdx,%rdx,2), %rax
movb (%rcx,%rax,4), %dl
movslq 0x4(%rcx,%rax,4), %rsi
movslq 0x8(%rcx,%rax,4), %rax
leaq (%rsi,%rsi,4), %rsi
addq %rdi, %rsi
movsbl (%rax,%rsi), %ecx
movb %dl, (%rax,%rsi)
testl %ecx, %ecx
je 0x80e7
cmpb $0x40, %cl
jg 0x80c8
movslq %ecx, %rax
addl $-0x31, %ecx
leaq (%rax,%rax,2), %rax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
shll %cl, %edx
movb $0x0, -0x20f(%rdi,%rax,4)
addl %edx, 0xd8(%rdi)
decl 0x34(%rdi)
jmp 0x80e7
addl $-0x41, %ecx
leaq (%rcx,%rcx,2), %rax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
shll %cl, %edx
movb $0x0, 0x85(%rdi,%rax,4)
addl %edx, 0xdc(%rdi)
decl 0x38(%rdi)
movq $-0x48, %rax
cmpl $0x4, 0x88(%rdi,%rax)
jne 0x8102
cmpl $0x4, 0x8c(%rdi,%rax)
je 0x8141
cmpl $0x0, 0xd0(%rdi,%rax)
jne 0x8116
cmpl $0x0, 0xd4(%rdi,%rax)
je 0x8148
addq $0xc, %rax
jne 0x80ee
movb 0xe4(%rdi), %cl
testb %cl, %cl
jne 0x8131
movl $0x1, %eax
cmpl $0x0, 0x38(%rdi)
je 0x814d
cmpl $0x0, 0x34(%rdi)
sete %al
andb %al, %cl
movzbl %cl, %eax
addl %eax, %eax
jmp 0x814d
movl $0x1, %eax
jmp 0x814d
movl $0x2, %eax
popq %rbp
retq
nop