// File: /workspace/github_cpp_makefile_star2_O1/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 0x7154(%rip), %rbx      # 0x11fd0
leaq 0x2746(%rip), %rsi      # 0xd5c9
movl $0x21, %edx
movq %rbx, %rdi
callq 0x31a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %rbx, %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
movq %r14, (%rsp)
jne 0xafa7
movq 0x38(%r15), %rax
movq 0x40(%r15), %rcx
subq %rax, %rcx
cmpq $0x9, %rcx
jb 0xb1a3
movl $0x1, %r14d
movl $0x2, %ebx
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %r13, %rbp
movq (%rax,%r14,8), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x2, %eax
jne 0xaf43
testq %rbp, %rbp
jne 0xaf43
movq 0x38(%r15), %rax
movq (%rax,%r14,8), %r13
cmpq $0x0, 0x38(%r13)
je 0xaf6d
movq 0x38(%r15), %rax
movq (%rax,%r14,8), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x2, %eax
jne 0xaf6a
testq %rbp, %rbp
je 0xaf6a
movq 0x38(%r15), %rax
movq (%rax,%r14,8), %rax
cmpq $0x0, 0x38(%rax)
je 0xaf8b
movq %rbp, %r13
movl %ebx, %r14d
movq 0x38(%r15), %rax
movq 0x40(%r15), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
incl %ebx
cmpq %r14, %rcx
ja 0xaf1d
jmp 0xb1a9
callq 0x3070
andl $0x80000001, %eax       # imm = 0x80000001
movq %rbp, %r13
cmpl $0x1, %eax
jne 0xaf6d
movq 0x38(%r15), %rax
movq (%rax,%r14,8), %r13
jmp 0xaf6d
movq (%r14), %rax
movq %r14, %rdi
callq *0x28(%rax)
cmpl $0x3, %eax
jne 0xb06a
movq 0x38(%r15), %rax
movq 0x40(%r15), %rcx
subq %rax, %rcx
cmpq $0x9, %rcx
jb 0xb1a3
movl $0x1, %r14d
movl $0x2, %ebx
xorl %r13d, %r13d
xorl %r12d, %r12d
movq %r12, %rbp
movq (%rax,%r14,8), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x2, %eax
jne 0xb006
testq %rbp, %rbp
jne 0xb006
movq 0x38(%r15), %rax
movq (%rax,%r14,8), %r12
cmpq $0x0, 0x30(%r12)
je 0xb030
movq 0x38(%r15), %rax
movq (%rax,%r14,8), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x2, %eax
jne 0xb02d
testq %rbp, %rbp
je 0xb02d
movq 0x38(%r15), %rax
movq (%rax,%r14,8), %rax
cmpq $0x0, 0x30(%rax)
je 0xb04e
movq %rbp, %r12
movl %ebx, %r14d
movq 0x38(%r15), %rax
movq 0x40(%r15), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
incl %ebx
cmpq %r14, %rcx
ja 0xafdf
jmp 0xb1a9
callq 0x3070
andl $0x80000001, %eax       # imm = 0x80000001
movq %rbp, %r12
cmpl $0x1, %eax
jne 0xb030
movq 0x38(%r15), %rax
movq (%rax,%r14,8), %r12
jmp 0xb030
movq (%r14), %rax
movq %r14, %rdi
callq *0x28(%rax)
cmpl $0x2, %eax
jne 0xb1a3
movq 0x38(%r15), %rax
movq 0x40(%r15), %rcx
subq %rax, %rcx
cmpq $0x9, %rcx
jb 0xb1a3
movl $0x1, %ebx
movl $0x2, %ebp
xorl %r12d, %r12d
xorl %r14d, %r14d
movq %r12, %r13
movq (%rax,%rbx,8), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x1, %eax
jne 0xb0c8
testq %r13, %r13
jne 0xb0c8
movq 0x38(%r15), %rax
movq (%rax,%rbx,8), %r12
cmpq $0x0, 0x30(%r12)
je 0xb0f2
movq 0x38(%r15), %rax
movq (%rax,%rbx,8), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x1, %eax
jne 0xb0ef
testq %r13, %r13
je 0xb0ef
movq 0x38(%r15), %rax
movq (%rax,%rbx,8), %rax
cmpq $0x0, 0x30(%rax)
je 0xb164
movq %r13, %r12
movq 0x38(%r15), %rax
movq (%rax,%rbx,8), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x3, %eax
jne 0xb119
testq %r14, %r14
jne 0xb119
movq 0x38(%r15), %rax
movq (%rax,%rbx,8), %r13
cmpq $0x0, 0x38(%r13)
je 0xb143
movq 0x38(%r15), %rax
movq (%rax,%rbx,8), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x3, %eax
jne 0xb140
testq %r14, %r14
je 0xb140
movq 0x38(%r15), %rax
movq (%rax,%rbx,8), %rax
cmpq $0x0, 0x38(%rax)
je 0xb187
movq %r14, %r13
movl %ebp, %ebx
movq 0x38(%r15), %rax
movq 0x40(%r15), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
incl %ebp
movq %r13, %r14
cmpq %rbx, %rcx
ja 0xb0a1
jmp 0xb1a9
callq 0x3070
andl $0x80000001, %eax       # imm = 0x80000001
movq %r13, %r12
cmpl $0x1, %eax
jne 0xb0f2
movq 0x38(%r15), %rax
movq (%rax,%rbx,8), %r12
jmp 0xb0f2
callq 0x3070
andl $0x80000001, %eax       # imm = 0x80000001
movq %r14, %r13
cmpl $0x1, %eax
jne 0xb143
movq 0x38(%r15), %rax
movq (%rax,%rbx,8), %r13
jmp 0xb143
xorl %r13d, %r13d
xorl %r12d, %r12d
testq %r13, %r13
movq (%rsp), %rdi
je 0xb1ba
movq %r13, 0x30(%rdi)
movq %rdi, 0x38(%r13)
testq %r12, %r12
je 0xb1c8
movq %r12, 0x38(%rdi)
movq %rdi, 0x30(%r12)
movq %r13, %rax
orq %r12, %rax
je 0xb204
callq 0xb7a2
testq %r13, %r13
je 0xb1e2
movq %r13, %rdi
callq 0xb7a2
testq %r12, %r12
je 0xb1ef
movq %r12, %rdi
callq 0xb7a2
movq 0x6dda(%rip), %rdi      # 0x11fd0
leaq 0x23ee(%rip), %rsi      # 0xd5eb
movl $0x24, %edx
jmp 0xb217
movq 0x6dc5(%rip), %rdi      # 0x11fd0
leaq 0x23fe(%rip), %rsi      # 0xd610
movl $0x21, %edx
callq 0x31a0
movq 0x6dad(%rip), %rbx      # 0x11fd0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3160
movsbl %al, %esi
movq %rbx, %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