// File: tyhsu[P]Ewn/game.cpp
// Function: Game::Game()
Game::Game()
{
	memset(this->board, 0, sizeof(this->board));
	memset(this->movable_chs_list, 0, sizeof(this->movable_chs_list));
	this->exist_chs_num_A = 6, this->exist_chs_num_B = 6;
	for (int i=0; i<6; i++)
		this->chs_list_A[i].assign('1'+i, true, 0, 0);
	for (int i=0; i<6; i++)
		this->chs_list_B[i].assign('A'+i, true, 0, 0);

	this->exist_bitwise_A = 0b111111;
	this->exist_bitwise_B = 0b111111;

	this->cur_chs_list_ptr = this->chs_list_A;
	this->cur_exist_bitwise_ptr = exist_bitwise_A;
	this->is_switch = false;

	//Initialize the positions of the chessmen
	//A: 1~6	B: A~F
	int chs_pos_index = 0;
	int chs_pos_A[6][2] = { {0,0}, {0,1}, {0,2}, {1,0}, {1,1}, {2,0} };
	int chs_pos_B[6][2] = { {4,4}, {4,3}, {4,2}, {3,4}, {3,3}, {2,4} };
	int (*current_chs_pos_ptr)[2] = &(chs_pos_A[0]);
	int chs_unuse_bitwise = 0b111111;
	char symbol_ = '1';
	srand( time(NULL) + getpid() );
	for (int i=0; i<2; i++) {
		//Every position selects a number
		while (chs_pos_index<6) {
			int chs_index = rand()%6;	//0~5
			if ((chs_unuse_bitwise & (1<<chs_index)) >> chs_index) {	//The number hasn't been used
				int x_ = current_chs_pos_ptr[chs_pos_index][0];
				int y_ = current_chs_pos_ptr[chs_pos_index][1];
				this->board[x_][y_] = symbol_ + chs_index;
				this->cur_chs_list_ptr[chs_index].x = x_;
				this->cur_chs_list_ptr[chs_index].y = y_;
				chs_pos_index++;
				chs_unuse_bitwise = chs_unuse_bitwise ^ (1<<chs_index);	//The used number is discarded
			}
		}
		chs_pos_index = 0;
		chs_unuse_bitwise = 0b111111;
		this->cur_chs_list_ptr = this->chs_list_B;
		current_chs_pos_ptr = chs_pos_B;
		symbol_ = 'A';
	}
	this->cur_chs_list_ptr = this->chs_list_A;	//recover the initialization
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
xorl %esi, %esi
movl $0x19, %edx
callq 0x2090
movq -0xb8(%rbp), %rdi
addq $0x1c, %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2090
movq -0xb8(%rbp), %rax
movl $0x6, 0x34(%rax)
movl $0x6, 0x38(%rax)
movl $0x0, -0xc(%rbp)
cmpl $0x6, -0xc(%rbp)
jge 0xa250
movq -0xb8(%rbp), %rdi
addq $0x3c, %rdi
movslq -0xc(%rbp), %rax
imulq $0xc, %rax, %rax
addq %rax, %rdi
movl -0xc(%rbp), %eax
addl $0x31, %eax
movb %al, -0xd(%rbp)
movb $0x1, -0xe(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
leaq -0xd(%rbp), %rsi
leaq -0xe(%rbp), %rdx
leaq -0x14(%rbp), %rcx
leaq -0x18(%rbp), %r8
callq 0xa110
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xa1f9
movl $0x0, -0x1c(%rbp)
cmpl $0x6, -0x1c(%rbp)
jge 0xa2b1
movq -0xb8(%rbp), %rdi
addq $0x84, %rdi
movslq -0x1c(%rbp), %rax
imulq $0xc, %rax, %rax
addq %rax, %rdi
movl -0x1c(%rbp), %eax
addl $0x41, %eax
movb %al, -0x1d(%rbp)
movb $0x1, -0x1e(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
leaq -0x1d(%rbp), %rsi
leaq -0x1e(%rbp), %rdx
leaq -0x24(%rbp), %rcx
leaq -0x28(%rbp), %r8
callq 0xa110
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xa257
movq -0xb8(%rbp), %rax
movl $0x3f, 0xd8(%rax)
movl $0x3f, 0xdc(%rax)
movq %rax, %rcx
addq $0x3c, %rcx
movq %rcx, 0xd0(%rax)
movl 0xd8(%rax), %ecx
movl %ecx, 0xe0(%rax)
movb $0x0, 0xe4(%rax)
movl $0x0, -0x2c(%rbp)
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x2090
movl $0x1, -0x54(%rbp)
movl $0x2, -0x4c(%rbp)
movl $0x1, -0x48(%rbp)
movl $0x1, -0x40(%rbp)
movl $0x1, -0x3c(%rbp)
movl $0x2, -0x38(%rbp)
leaq -0x90(%rbp), %rdi
leaq 0x34b4(%rip), %rsi      # 0xd7f0
movl $0x30, %edx
callq 0x2110
leaq -0x60(%rbp), %rax
movq %rax, -0x98(%rbp)
movl $0x3f, -0x9c(%rbp)
movb $0x31, -0x9d(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x2130
movq %rax, -0xc0(%rbp)
callq 0x21d0
movl %eax, %ecx
movq -0xc0(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movl %eax, %edi
callq 0x2140
movl $0x0, -0xa4(%rbp)
cmpl $0x2, -0xa4(%rbp)
jge 0xa500
jmp 0xa3a6
cmpl $0x6, -0x2c(%rbp)
jge 0xa4ae
callq 0x2050
movl $0x6, %ecx
cltd
idivl %ecx
movl %edx, -0xa8(%rbp)
movl -0x9c(%rbp), %eax
movl -0xa8(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
movl -0xa8(%rbp), %ecx
sarl %cl, %eax
cmpl $0x0, %eax
je 0xa4a9
movq -0xb8(%rbp), %rax
movq -0x98(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
movl (%rcx,%rdx,8), %ecx
movl %ecx, -0xac(%rbp)
movq -0x98(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
movl 0x4(%rcx,%rdx,8), %ecx
movl %ecx, -0xb0(%rbp)
movsbl -0x9d(%rbp), %ecx
addl -0xa8(%rbp), %ecx
movb %cl, %sil
movslq -0xac(%rbp), %rcx
imulq $0x5, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movslq -0xb0(%rbp), %rdx
movb %sil, (%rcx,%rdx)
movl -0xac(%rbp), %edx
movq 0xd0(%rax), %rcx
movslq -0xa8(%rbp), %rsi
imulq $0xc, %rsi, %rsi
addq %rsi, %rcx
movl %edx, 0x4(%rcx)
movl -0xb0(%rbp), %ecx
movq 0xd0(%rax), %rax
movslq -0xa8(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x9c(%rbp), %eax
movl -0xa8(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
xorl %ecx, %eax
movl %eax, -0x9c(%rbp)
jmp 0xa3a6
movq -0xb8(%rbp), %rax
movl $0x0, -0x2c(%rbp)
movl $0x3f, -0x9c(%rbp)
movq %rax, %rcx
addq $0x84, %rcx
movq %rcx, 0xd0(%rax)
leaq -0x90(%rbp), %rax
movq %rax, -0x98(%rbp)
movb $0x41, -0x9d(%rbp)
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0xa397
movq -0xb8(%rbp), %rax
movq %rax, %rcx
addq $0x3c, %rcx
movq %rcx, 0xd0(%rax)
addq $0xc0, %rsp
popq %rbp
retq
nop