// File: 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
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x58(%rbp)
movq 0xd0(%rdi), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x24(%rbp)
movl 0x8(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x28(%rbp)
movb 0xe4(%rdi), %al
andb $0x1, %al
movzbl %al, %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl $0x0, %edx
cmovel %ecx, %eax
movl %eax, -0x2c(%rbp)
movq -0x24(%rbp), %rax
movq %rax, -0x3c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x34(%rbp)
movb $0x0, -0x3c(%rbp)
leaq -0x3c(%rbp), %rsi
callq 0xb0b0
movq -0x58(%rbp), %rax
movl $0x0, -0x40(%rbp)
testb $0x1, 0xe4(%rax)
jne 0xb1bd
movsbl -0x24(%rbp), %eax
subl $0x31, %eax
movl %eax, -0x40(%rbp)
jmp 0xb1c7
movsbl -0x24(%rbp), %eax
subl $0x41, %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0xb1ed
movq -0x58(%rbp), %rax
movq 0xd0(%rax), %rdi
movslq -0x40(%rbp), %rax
imulq $0xc, %rax, %rax
addq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0xa160
jmp 0xb259
cmpl $0x1, -0x28(%rbp)
jne 0xb213
movq -0x58(%rbp), %rax
movq 0xd0(%rax), %rdi
movslq -0x40(%rbp), %rax
imulq $0xc, %rax, %rax
addq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0xa180
jmp 0xb257
cmpl $0x2, -0x28(%rbp)
jne 0xb255
movq -0x58(%rbp), %rax
movq 0xd0(%rax), %rdi
movslq -0x40(%rbp), %rax
imulq $0xc, %rax, %rax
addq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0xa160
movq -0x58(%rbp), %rax
movq 0xd0(%rax), %rdi
movslq -0x40(%rbp), %rax
imulq $0xc, %rax, %rax
addq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0xa180
jmp 0xb257
jmp 0xb259
movq -0x58(%rbp), %rdi
movq 0xd0(%rdi), %rax
movslq -0x40(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x4c(%rbp)
movl 0x8(%rax), %eax
movl %eax, -0x44(%rbp)
leaq -0x4c(%rbp), %rsi
addq $0x4, %rsi
leaq -0x4c(%rbp), %rdx
addq $0x8, %rdx
callq 0xb0f0
movq -0x58(%rbp), %rdi
movb %al, -0x2d(%rbp)
leaq -0x4c(%rbp), %rsi
callq 0xb0b0
movsbl -0x2d(%rbp), %eax
cmpl $0x0, %eax
je 0xb348
movsbl -0x2d(%rbp), %eax
cmpl $0x41, %eax
jge 0xb2fe
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x3c, %rcx
movsbl -0x2d(%rbp), %edx
subl $0x31, %edx
movslq %edx, %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movb $0x0, 0x1(%rcx)
movsbl -0x2d(%rbp), %ecx
subl $0x31, %ecx
movl $0x1, %edx
shll %cl, %edx
movl 0xd8(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xd8(%rax)
movl 0x34(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x34(%rax)
jmp 0xb346
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x84, %rcx
movsbl -0x2d(%rbp), %edx
subl $0x41, %edx
movslq %edx, %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movb $0x0, 0x1(%rcx)
movsbl -0x2d(%rbp), %ecx
subl $0x41, %ecx
movl $0x1, %edx
shll %cl, %edx
movl 0xdc(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xdc(%rax)
movl 0x38(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x38(%rax)
jmp 0xb348
movl $0x0, -0x50(%rbp)
cmpl $0x6, -0x50(%rbp)
jge 0xb3e6
movq -0x58(%rbp), %rax
addq $0x3c, %rax
movslq -0x50(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x4, 0x4(%rax)
jne 0xb397
movq -0x58(%rbp), %rax
addq $0x3c, %rax
movslq -0x50(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x4, 0x8(%rax)
jne 0xb397
movl $0x1, -0x4(%rbp)
jmp 0xb42f
movq -0x58(%rbp), %rax
addq $0x84, %rax
movslq -0x50(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x4(%rax)
jne 0xb3d6
movq -0x58(%rbp), %rax
addq $0x84, %rax
movslq -0x50(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x8(%rax)
jne 0xb3d6
movl $0x2, -0x4(%rbp)
jmp 0xb42f
jmp 0xb3d8
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0xb34f
movq -0x58(%rbp), %rax
testb $0x1, 0xe4(%rax)
jne 0xb406
movq -0x58(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jne 0xb406
movl $0x1, -0x4(%rbp)
jmp 0xb42f
movq -0x58(%rbp), %rax
testb $0x1, 0xe4(%rax)
je 0xb426
movq -0x58(%rbp), %rax
cmpl $0x0, 0x34(%rax)
jne 0xb426
movl $0x2, -0x4(%rbp)
jmp 0xb42f
jmp 0xb428
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)