// File: /workspace/github_cpp_makefile_star2_O3/AngelPn[P]L5R-card_game/src/Player.cpp
// Function: Player::checkChains(Holding*)
void Player::checkChains(Holding* holding)
{
	cout << "Checking for possible chains ... " << endl << endl;

	Holding* upper = NULL;
	Holding* sub = NULL;
	if (holding->getHoldingType() == MINE) //if holding is mine you search for possible upper holding connections
	{
		for (unsigned int i = 1; i < holdings.size(); i++)  //you go through all players holdings other than stronghold obviously
		{
			if (holdings[i]->getHoldingType() == GOLD_MINE && upper == NULL && holdings[i]->hasSub() == false ) //chain goes mine --> gold mine
				upper = holdings[i];
			else if (holdings[i]->getHoldingType() == GOLD_MINE && upper != NULL &&
					holdings[i]->hasSub() == false && rand()%2 == 1) //if another gold mine is found choose in random
				upper = holdings[i];
		}

	}

	else if (holding->getHoldingType() == CRYSTAL_MINE) //if holding is crystal mine you search for possible sub holding connections
	{
		for (unsigned int i = 1; i < holdings.size(); i++)
		{
			if (holdings[i]->getHoldingType() == GOLD_MINE && sub == NULL && holdings[i]->hasUpper() == false) //chain goes crystal mine <-- gold mine
				sub = holdings[i];
			else if (holdings[i]->getHoldingType() == GOLD_MINE && sub != NULL &&
					holdings[i]->hasUpper() == false && rand()%2 == 1) //if another gold mine is found choose in random
				sub = holdings[i];
		}

	}

	else if (holding->getHoldingType() == GOLD_MINE) //if holding is gold mine you search for possible upper AND sub holding connections
	{
		for (unsigned int i = 1; i < holdings.size(); i++)
		{
			if (holdings[i]->getHoldingType() == MINE && sub == NULL && holdings[i]->hasUpper() == false) //chain goes gold mine <-- mine
				sub = holdings[i];
			else if (holdings[i]->getHoldingType() == MINE && sub != NULL &&
					holdings[i]->hasUpper() == false && rand()%2 == 1) //if another mine is found choose in random
				sub = holdings[i];

			if (holdings[i]->getHoldingType() == CRYSTAL_MINE && upper == NULL && holdings[i]->hasSub() == false) //chaing goes mine --> gold mine --> crystal mine
				upper = holdings[i];
			else if (holdings[i]->getHoldingType() == CRYSTAL_MINE && upper != NULL &&
					holdings[i]->hasSub() == false && rand()%2 == 1) //if another mine is found choose in random
				upper = holdings[i];
		}

	}

	if (upper != NULL){ //if a possible upper holding connection is decided
		holding->setUpperHolding(upper);  //make connection
		upper->setSubHolding(holding);	  //connection is two-way
	}
	if (sub != NULL){ //if a possible sub holding connection is decided
		holding->setSubHolding(sub); 	  //make connection
		sub->setUpperHolding(holding);	  //connection is two-way	
	}

	if (upper != NULL || sub !=NULL) //if at least one connection was made
	{
		holding->equipBonus();  //update harvest value of holding with bonus
		if(upper!=NULL)
			upper->equipBonus(); //update harvest value of upper with bonus, if it exists 
		if(sub!=NULL)
			sub->equipBonus();   //update harvest value of sub with bonus, if it exists
		cout << "Connections made , bonuses equipped " << endl << endl;
	}

	else
		cout << "No possible connections found :( " << endl << endl;
 //obviously if given holding is not mine or gold mine or crystal mine nothing happens and we just move on with our day


}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %r15
movq 0x7012(%rip), %rbp      # 0x11fd0
leaq 0x25f0(%rip), %rsi      # 0xd5b5
movl $0x21, %edx
movq %rbp, %rdi
callq 0x31a0
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %rbp, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq (%r14), %rax
movq %r14, %rdi
callq *0x28(%rax)
cmpl $0x1, %eax
jne 0xb0e5
movq 0x38(%r15), %rcx
movq 0x40(%r15), %rax
subq %rcx, %rax
cmpq $0x9, %rax
jb 0xb2fe
movl $0x1, %ebp
movl $0x2, %ebx
xorl %r12d, %r12d
xorl %r13d, %r13d
movq (%rcx,%rbp,8), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
movq 0x38(%r15), %rcx
movq (%rcx,%rbp,8), %rdi
cmpl $0x2, %eax
jne 0xb07e
testq %r13, %r13
jne 0xb07e
cmpq $0x0, 0x38(%rdi)
je 0xb0b6
movq (%rdi), %rax
callq *0x28(%rax)
movq 0x38(%r15), %rcx
cmpl $0x2, %eax
jne 0xb0b9
testq %r13, %r13
je 0xb0b9
movq (%rcx,%rbp,8), %rax
cmpq $0x0, 0x38(%rax)
jne 0xb0b9
callq 0x3070
andl $0x80000001, %eax       # imm = 0x80000001
movq 0x38(%r15), %rcx
cmpl $0x1, %eax
jne 0xb0b9
movq (%rcx,%rbp,8), %r13
jmp 0xb0b9
movq %rdi, %r13
movl %ebx, %ebp
movq 0x40(%r15), %rax
subq %rcx, %rax
sarq $0x3, %rax
incl %ebx
cmpq %rbp, %rax
ja 0xb05b
testq %r13, %r13
je 0xb2a7
movq %r13, 0x30(%r14)
movq %r14, 0x38(%r13)
movb $0x1, %bl
jmp 0xb2ac
movq (%r14), %rax
movq %r14, %rdi
callq *0x28(%rax)
cmpl $0x3, %eax
jne 0xb197
movq 0x38(%r15), %rcx
movq 0x40(%r15), %rax
subq %rcx, %rax
cmpq $0x9, %rax
jb 0xb2fe
movl $0x1, %r13d
movl $0x2, %ebx
xorl %r12d, %r12d
movq (%rcx,%r13,8), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
movq 0x38(%r15), %rcx
movq (%rcx,%r13,8), %rdi
cmpl $0x2, %eax
jne 0xb13d
testq %r12, %r12
jne 0xb13d
cmpq $0x0, 0x30(%rdi)
je 0xb175
movq (%rdi), %rax
callq *0x28(%rax)
movq 0x38(%r15), %rcx
cmpl $0x2, %eax
jne 0xb178
testq %r12, %r12
je 0xb178
movq (%rcx,%r13,8), %rax
cmpq $0x0, 0x30(%rax)
jne 0xb178
callq 0x3070
andl $0x80000001, %eax       # imm = 0x80000001
movq 0x38(%r15), %rcx
cmpl $0x1, %eax
jne 0xb178
movq (%rcx,%r13,8), %r12
jmp 0xb178
movq %rdi, %r12
movl %ebx, %r13d
movq 0x40(%r15), %rax
subq %rcx, %rax
sarq $0x3, %rax
incl %ebx
cmpq %r13, %rax
ja 0xb11a
xorl %ebx, %ebx
xorl %r13d, %r13d
jmp 0xb2b3
movq (%r14), %rax
movq %r14, %rdi
callq *0x28(%rax)
cmpl $0x2, %eax
jne 0xb2fe
movq 0x38(%r15), %rcx
movq 0x40(%r15), %rax
subq %rcx, %rax
cmpq $0x9, %rax
jb 0xb2fe
movl $0x1, %ebx
movl $0x2, %ebp
xorl %r12d, %r12d
xorl %r13d, %r13d
movq (%rcx,%rbx,8), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
movq 0x38(%r15), %rcx
movq (%rcx,%rbx,8), %rdi
cmpl $0x1, %eax
jne 0xb1f1
testq %r12, %r12
jne 0xb1f1
cmpq $0x0, 0x30(%rdi)
je 0xb229
movq (%rdi), %rax
callq *0x28(%rax)
movq 0x38(%r15), %rcx
cmpl $0x1, %eax
jne 0xb22c
testq %r12, %r12
je 0xb22c
movq (%rcx,%rbx,8), %rax
cmpq $0x0, 0x30(%rax)
jne 0xb22c
callq 0x3070
andl $0x80000001, %eax       # imm = 0x80000001
movq 0x38(%r15), %rcx
cmpl $0x1, %eax
jne 0xb22c
movq (%rcx,%rbx,8), %r12
jmp 0xb22c
movq %rdi, %r12
movq (%rcx,%rbx,8), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
movq 0x38(%r15), %rcx
movq (%rcx,%rbx,8), %rdi
cmpl $0x3, %eax
jne 0xb24f
testq %r13, %r13
jne 0xb24f
cmpq $0x0, 0x38(%rdi)
je 0xb287
movq (%rdi), %rax
callq *0x28(%rax)
movq 0x38(%r15), %rcx
cmpl $0x3, %eax
jne 0xb28a
testq %r13, %r13
je 0xb28a
movq (%rcx,%rbx,8), %rax
cmpq $0x0, 0x38(%rax)
jne 0xb28a
callq 0x3070
andl $0x80000001, %eax       # imm = 0x80000001
movq 0x38(%r15), %rcx
cmpl $0x1, %eax
jne 0xb28a
movq (%rcx,%rbx,8), %r13
jmp 0xb28a
movq %rdi, %r13
movl %ebp, %ebx
movq 0x40(%r15), %rax
subq %rcx, %rax
sarq $0x3, %rax
incl %ebp
cmpq %rbx, %rax
ja 0xb1ce
jmp 0xb0cd
xorl %ebx, %ebx
xorl %r13d, %r13d
movq 0x6d1d(%rip), %rbp      # 0x11fd0
testq %r12, %r12
je 0xb2d2
movq %r12, 0x38(%r14)
movq %r14, 0x30(%r12)
movq %r14, %rdi
callq 0xb89a
movq %r13, %r14
testb %bl, %bl
jne 0xb2d9
jmp 0xb2e1
movq %r13, %r12
testb %bl, %bl
je 0xb2fe
movq %r14, %rdi
callq 0xb89a
movq %r12, %rdi
callq 0xb89a
movq 0x6ce0(%rip), %rdi      # 0x11fd0
leaq 0x22e0(%rip), %rsi      # 0xd5d7
movl $0x24, %edx
jmp 0xb311
movq 0x6ccb(%rip), %rdi      # 0x11fd0
leaq 0x22f0(%rip), %rsi      # 0xd5fc
movl $0x21, %edx
callq 0x31a0
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %rbp, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x30f0