// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
xorps %xmm0, %xmm0
movups %xmm0, 0x9(%rdi)
movups %xmm0, (%rdi)
movups %xmm0, 0x1c(%rdi)
andq $0x0, 0x2c(%rdi)
movabsq $0x600000006, %rax      # imm = 0x600000006
movq %rax, 0x34(%rdi)
movq %rdi, -0x30(%rbp)
leaq 0x3c(%rdi), %rdx
movb $0x31, %al
xorl %ecx, %ecx
cmpq $0x48, %rcx
je 0x61b4
movb %al, (%rdx,%rcx)
movb $0x1, 0x1(%rdx,%rcx)
andq $0x0, 0x4(%rdx,%rcx)
incb %al
addq $0xc, %rcx
jmp 0x6198
movq -0x30(%rbp), %rax
leaq 0x84(%rax), %r12
movb $0x41, %al
xorl %ecx, %ecx
cmpq $0x48, %rcx
je 0x61e1
movb %al, (%r12,%rcx)
movb $0x1, 0x1(%r12,%rcx)
andq $0x0, 0x4(%r12,%rcx)
incb %al
addq $0xc, %rcx
jmp 0x61c3
movabsq $0x3f0000003f, %rax     # imm = 0x3F0000003F
movq -0x30(%rbp), %rcx
movq %rax, 0xd8(%rcx)
movq %rdx, -0x48(%rbp)
movq %rdx, 0xd0(%rcx)
movl $0x3f, 0xe0(%rcx)
movb $0x0, 0xe4(%rcx)
xorps %xmm0, %xmm0
leaq -0x80(%rbp), %rcx
movaps %xmm0, (%rcx)
movaps %xmm0, 0x10(%rcx)
movaps %xmm0, 0x20(%rcx)
movl $0x1, 0xc(%rcx)
movabsq $0x100000002, %rax      # imm = 0x100000002
movq %rax, 0x14(%rcx)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x20(%rcx)
movq %rcx, -0x40(%rbp)
movl $0x2, 0x28(%rcx)
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x2130
movq %rax, %rbx
callq 0x21d0
addl %eax, %ebx
movl %ebx, %edi
callq 0x2140
pushq $0x31
popq %rax
movq %rax, -0x38(%rbp)
pushq $0x6
popq %r15
pushq $0x1
popq %rbx
movq %r12, -0x50(%rbp)
cmpl $0x2, %r14d
je 0x6317
xorl %r12d, %r12d
pushq $0x3f
popq %r13
cmpl $0x5, %r12d
ja 0x62ee
callq 0x2050
cltd
idivl %r15d
movl %edx, %ecx
movl %ebx, %eax
shll %cl, %eax
btl %edx, %r13d
jae 0x6290
movl %r12d, %edx
movq -0x40(%rbp), %rdi
movslq (%rdi,%rdx,8), %rsi
movslq 0x4(%rdi,%rdx,8), %rdx
movq -0x38(%rbp), %rdi
addl %ecx, %edi
leaq (%rsi,%rsi,4), %r8
movq -0x30(%rbp), %r9
addq %r9, %r8
movb %dil, (%rdx,%r8)
movq 0xd0(%r9), %rdi
movslq %ecx, %rcx
imulq $0xc, %rcx, %rcx
movl %esi, 0x4(%rdi,%rcx)
movl %edx, 0x8(%rdi,%rcx)
incl %r12d
xorl %eax, %r13d
jmp 0x6290
movq -0x30(%rbp), %rax
movq -0x50(%rbp), %r12
movq %r12, 0xd0(%rax)
incl %r14d
leaq 0x24f9(%rip), %rax      # 0x8800
movq %rax, -0x40(%rbp)
pushq $0x41
popq %rax
movq %rax, -0x38(%rbp)
jmp 0x627f
movq -0x30(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, 0xd0(%rax)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop