// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x9(%rdi)
movups %xmm0, (%rdi)
movups %xmm0, 0x1c(%rdi)
movq $0x0, 0x2c(%rdi)
movabsq $0x600000006, %rax      # imm = 0x600000006
movq %rax, 0x34(%rdi)
leaq 0x3c(%rdi), %rdx
movb $0x31, %al
xorl %ecx, %ecx
movb %al, (%rdx,%rcx)
movb $0x1, 0x1(%rdx,%rcx)
movq $0x0, 0x4(%rdx,%rcx)
incb %al
addq $0xc, %rcx
cmpq $0x48, %rcx
jne 0x774a
leaq 0x84(%rbx), %r12
movb $0x41, %al
xorl %ecx, %ecx
movb %al, (%r12,%rcx)
movb $0x1, 0x1(%r12,%rcx)
movq $0x0, 0x4(%r12,%rcx)
incb %al
addq $0xc, %rcx
cmpq $0x48, %rcx
jne 0x7772
movabsq $0x3f0000003f, %rax     # imm = 0x3F0000003F
movq %rax, 0xd8(%rbx)
movq %rdx, -0x38(%rbp)
movq %rdx, 0xd0(%rbx)
movl $0x3f, 0xe0(%rbx)
movb $0x0, 0xe4(%rbx)
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %r13
movaps %xmm0, (%r13)
movaps %xmm0, 0x10(%r13)
movaps %xmm0, 0x20(%r13)
movl $0x1, 0xc(%r13)
movabsq $0x100000002, %rax      # imm = 0x100000002
movq %rax, 0x14(%r13)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x20(%r13)
movl $0x2, 0x28(%r13)
xorl %edi, %edi
callq 0x2110
movq %rax, %r14
callq 0x21b0
addl %eax, %r14d
movl %r14d, %edi
callq 0x2120
movl $0x31, %r15d
movb $0x1, %al
movq %r12, -0x40(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x3f, %r12d
xorl %r14d, %r14d
callq 0x2060
movslq %eax, %rcx
imulq $0x2aaaaaab, %rcx, %rax # imm = 0x2AAAAAAB
movq %rax, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rax
addl %edx, %eax
addl %eax, %eax
leal (%rax,%rax,2), %eax
subl %eax, %ecx
movl $0x1, %eax
shll %cl, %eax
btl %ecx, %r12d
jae 0x789a
movslq %r14d, %r14
movslq (%r13,%r14,8), %rdx
movslq 0x4(%r13,%r14,8), %rsi
leal (%rcx,%r15), %edi
leaq (%rdx,%rdx,4), %r8
addq %rbx, %r8
movb %dil, (%rsi,%r8)
movq 0xd0(%rbx), %rdi
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
movl %edx, 0x4(%rdi,%rcx,4)
movl %esi, 0x8(%rdi,%rcx,4)
incl %r14d
xorl %eax, %r12d
cmpl $0x6, %r14d
jl 0x7832
movq -0x40(%rbp), %r12
movq %r12, 0xd0(%rbx)
movl $0x41, %r15d
leaq 0x1f48(%rip), %r13      # 0x9800
testb $0x1, -0x2c(%rbp)
movl $0x0, %eax
jne 0x7826
movq -0x38(%rbp), %rax
movq %rax, 0xd0(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop