// File: /workspace/github_cpp_makefile_star2_O1/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), %r8
movslq 0x4(%rax,%rcx,4), %r9
movslq 0x8(%rax,%rcx,4), %rcx
movl 0x4(%rsi), %edx
movzbl 0xe4(%rdi), %eax
negl %eax
orl $0x1, %eax
leaq (%r9,%r9,4), %rsi
addq %rdi, %rsi
movb $0x0, (%rcx,%rsi)
movzbl 0xe4(%rdi), %ecx
xorl $0x1, %ecx
shll $0x4, %ecx
leaq (%rcx,%r8), %rsi
addq $-0x41, %rsi
movslq %esi, %rcx
cmpl $0x2, %edx
je 0x8219
cmpl $0x1, %edx
je 0x8204
testl %edx, %edx
jne 0x8231
movq 0xd0(%rdi), %rdx
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,4), %rdx
addq $0x4, %rdx
jmp 0x822f
movq 0xd0(%rdi), %rdx
leaq (%rcx,%rcx,2), %rsi
leaq (%rdx,%rsi,4), %rdx
addq $0x8, %rdx
jmp 0x822f
movq 0xd0(%rdi), %rdx
leaq (%rcx,%rcx,2), %rsi
leaq (%rdx,%rsi,4), %rdx
addq $0x8, %rdx
addl %eax, -0x4(%rdx)
addl %eax, (%rdx)
movq 0xd0(%rdi), %rax
leaq (%rcx,%rcx,2), %rcx
movb (%rax,%rcx,4), %dl
movslq 0x4(%rax,%rcx,4), %rsi
movslq 0x8(%rax,%rcx,4), %rax
leaq (%rsi,%rsi,4), %rsi
addq %rdi, %rsi
movsbl (%rax,%rsi), %ecx
movb %dl, (%rax,%rsi)
testl %ecx, %ecx
je 0x82a3
cmpb $0x40, %cl
jg 0x8284
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 0x82a3
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)
leaq 0x8c(%rdi), %rdx
xorl %esi, %esi
xorl %ecx, %ecx
cmpl $0x4, -0x4c(%rdx)
jne 0x82ba
cmpl $0x4, -0x48(%rdx)
je 0x82df
cmpl $0x0, -0x4(%rdx)
jne 0x82c5
cmpl $0x0, (%rdx)
je 0x82e6
cmpq $0x5, %rsi
leaq 0x1(%rsi), %r8
setae %cl
addq $0xc, %rdx
movq %r8, %rsi
cmpq $0x6, %r8
jne 0x82ae
jmp 0x82eb
movl $0x1, %eax
jmp 0x82eb
movl $0x2, %eax
testb $0x1, %cl
je 0x8313
movb 0xe4(%rdi), %cl
testb %cl, %cl
jne 0x8305
movl $0x1, %eax
cmpl $0x0, 0x38(%rdi)
je 0x8313
cmpl $0x0, 0x34(%rdi)
sete %al
andb %al, %cl
movzbl %cl, %eax
addl %eax, %eax
popq %rbp
retq
nop