// File: /workspace/github_cpp_makefile_star2_O1/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)
movb $0x31, %al
xorl %ecx, %ecx
movb %al, 0x3c(%rbx,%rcx)
movb $0x1, 0x3d(%rbx,%rcx)
movq $0x0, 0x40(%rbx,%rcx)
incb %al
addq $0xc, %rcx
cmpq $0x48, %rcx
jne 0x78c6
movb $0x41, %al
xorl %ecx, %ecx
movb %al, 0x84(%rbx,%rcx)
movb $0x1, 0x85(%rbx,%rcx)
movq $0x0, 0x88(%rbx,%rcx)
incb %al
addq $0xc, %rcx
cmpq $0x48, %rcx
jne 0x78e8
movabsq $0x3f0000003f, %rax     # imm = 0x3F0000003F
movq %rax, 0xd8(%rbx)
leaq 0x3c(%rbx), %rax
movq %rax, -0x30(%rbp)
movq %rax, 0xd0(%rbx)
movl $0x3f, 0xe0(%rbx)
movb $0x0, 0xe4(%rbx)
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %r12
movaps %xmm0, (%r12)
movaps %xmm0, 0x10(%r12)
movaps %xmm0, 0x20(%r12)
movl $0x1, 0xc(%r12)
movabsq $0x100000002, %rax      # imm = 0x100000002
movq %rax, 0x14(%r12)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x20(%r12)
movl $0x2, 0x28(%r12)
xorl %r13d, %r13d
xorl %edi, %edi
callq 0x2110
movq %rax, %r14
callq 0x21b0
addl %eax, %r14d
movl %r14d, %edi
callq 0x2120
leaq 0x84(%rbx), %rax
movq %rax, -0x38(%rbp)
movl $0x31, %r15d
movq %r13, -0x40(%rbp)
movl $0x3f, %r14d
xorl %r13d, %r13d
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, %r14d
jae 0x7a2a
movslq %r13d, %r13
movslq (%r12,%r13,8), %rdx
movslq 0x4(%r12,%r13,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 %r13d
xorl %eax, %r14d
cmpl $0x6, %r13d
jl 0x79c3
movq -0x38(%rbp), %rax
movq %rax, 0xd0(%rbx)
movq -0x40(%rbp), %rcx
leal 0x1(%rcx), %eax
movl $0x41, %r15d
leaq 0x1db1(%rip), %r12      # 0x9800
testl %ecx, %ecx
movl %eax, %r13d
je 0x79b6
movq -0x30(%rbp), %rax
movq %rax, 0xd0(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq