// File: /workspace/github_cpp_makefile_star2_O2/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
imulq $0xc, %rcx, %rcx
movsbq (%rax,%rcx), %rdx
movslq 0x4(%rax,%rcx), %r8
movslq 0x8(%rax,%rcx), %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 0x69ab
cmpl $0x1, %esi
je 0x699e
testl %esi, %esi
jne 0x69bb
imulq $0xc, %rdx, %rsi
addq %rcx, %rsi
addq $0x4, %rsi
jmp 0x69b9
imulq $0xc, %rdx, %rsi
addq %rcx, %rsi
addq $0x8, %rsi
jmp 0x69b9
imulq $0xc, %rdx, %rsi
addq %rcx, %rsi
addq $0x8, %rsi
addl %eax, -0x4(%rsi)
addl %eax, (%rsi)
imulq $0xc, %rdx, %rax
movb (%rcx,%rax), %dl
movslq 0x4(%rcx,%rax), %rsi
movslq 0x8(%rcx,%rax), %rax
leaq (%rsi,%rsi,4), %rsi
addq %rdi, %rsi
movsbl (%rax,%rsi), %ecx
movb %dl, (%rax,%rsi)
testl %ecx, %ecx
je 0x6a26
cmpb $0x40, %cl
jg 0x6a07
movslq %ecx, %rax
addl $-0x31, %ecx
imulq $0xc, %rax, %rax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
shll %cl, %edx
movb $0x0, -0x20f(%rdi,%rax)
addl %edx, 0xd8(%rdi)
decl 0x34(%rdi)
jmp 0x6a26
addl $-0x41, %ecx
imulq $0xc, %rcx, %rax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
shll %cl, %edx
movb $0x0, 0x85(%rdi,%rax)
addl %edx, 0xdc(%rdi)
decl 0x38(%rdi)
movabsq $-0x48, %rcx
movl $0x1, %eax
movl $0x2, %edx
testq %rcx, %rcx
je 0x6a6d
cmpl $0x4, 0x88(%rdi,%rcx)
jne 0x6a53
cmpl $0x4, 0x8c(%rdi,%rcx)
je 0x6a8f
cmpl $0x0, 0xd0(%rdi,%rcx)
jne 0x6a67
cmpl $0x0, 0xd4(%rdi,%rcx)
je 0x6a8d
addq $0xc, %rcx
jmp 0x6a3a
movb 0xe4(%rdi), %cl
testb %cl, %cl
jne 0x6a7d
cmpl $0x0, 0x38(%rdi)
je 0x6a8f
cmpl $0x0, 0x34(%rdi)
sete %al
andb %al, %cl
movzbl %cl, %eax
addl %eax, %eax
jmp 0x6a8f
movl %edx, %eax
popq %rbp
retq
nop