// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq 0x12461(%rip), %rdi     # 0x24fd0
leaq 0x68e2(%rip), %rsi      # 0x19458
callq 0x4200
movq %rax, %rdi
movq 0x1243b(%rip), %rsi     # 0x24fc0
callq 0x4230
movq %rax, %rdi
movq 0x1242c(%rip), %rsi     # 0x24fc0
callq 0x4230
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x1, %eax
jne 0x12cda
movl $0x1, -0x24(%rbp)
movq -0x38(%rbp), %rdi
movl -0x24(%rbp), %eax
movq %rax, -0x40(%rbp)
addq $0x38, %rdi
callq 0x13910
movq %rax, %rcx
movq -0x40(%rbp), %rax
cmpq %rcx, %rax
jae 0x12cd5
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x24(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x2, %eax
jne 0x12c4d
cmpq $0x0, -0x18(%rbp)
jne 0x12c4d
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x24(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rdi
callq 0x14530
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x12c4d
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x24(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x12cc5
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x24(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x2, %eax
jne 0x12cc3
cmpq $0x0, -0x18(%rbp)
je 0x12cc3
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x24(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rdi
callq 0x14530
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x12cc3
callq 0x40b0
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0x12cc3
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x24(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x12cc5
jmp 0x12cc7
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x12bc3
jmp 0x1301b
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x3, %eax
jne 0x12e0b
movl $0x1, -0x28(%rbp)
movq -0x38(%rbp), %rdi
movl -0x28(%rbp), %eax
movq %rax, -0x48(%rbp)
addq $0x38, %rdi
callq 0x13910
movq %rax, %rcx
movq -0x48(%rbp), %rax
cmpq %rcx, %rax
jae 0x12e06
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x28(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x2, %eax
jne 0x12d7e
cmpq $0x0, -0x20(%rbp)
jne 0x12d7e
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x28(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rdi
callq 0x14550
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x12d7e
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x28(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x12df6
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x28(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x2, %eax
jne 0x12df4
cmpq $0x0, -0x20(%rbp)
je 0x12df4
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x28(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rdi
callq 0x14550
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x12df4
callq 0x40b0
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0x12df4
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x28(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x12df6
jmp 0x12df8
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x12cf4
jmp 0x13019
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x2, %eax
jne 0x13017
movl $0x1, -0x2c(%rbp)
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %eax
movq %rax, -0x50(%rbp)
addq $0x38, %rdi
callq 0x13910
movq %rax, %rcx
movq -0x50(%rbp), %rax
cmpq %rcx, %rax
jae 0x13015
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x2c(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x1, %eax
jne 0x12eaf
cmpq $0x0, -0x20(%rbp)
jne 0x12eaf
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x2c(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rdi
callq 0x14550
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x12eaf
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x2c(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x12f27
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x2c(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x1, %eax
jne 0x12f25
cmpq $0x0, -0x20(%rbp)
je 0x12f25
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x2c(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rdi
callq 0x14550
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x12f25
callq 0x40b0
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0x12f25
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x2c(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x12f27
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x2c(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x3, %eax
jne 0x12f8d
cmpq $0x0, -0x18(%rbp)
jne 0x12f8d
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x2c(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rdi
callq 0x14530
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x12f8d
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x2c(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x13005
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x2c(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x3, %eax
jne 0x13003
cmpq $0x0, -0x18(%rbp)
je 0x13003
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x2c(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rdi
callq 0x14530
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x13003
callq 0x40b0
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0x13003
movq -0x38(%rbp), %rdi
addq $0x38, %rdi
movl -0x2c(%rbp), %eax
movl %eax, %esi
callq 0x13770
movq (%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x13005
jmp 0x13007
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x12e25
jmp 0x13017
jmp 0x13019
jmp 0x1301b
cmpq $0x0, -0x18(%rbp)
je 0x1303c
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x14570
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x14590
cmpq $0x0, -0x20(%rbp)
je 0x1305d
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x14590
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x14570
cmpq $0x0, -0x18(%rbp)
jne 0x1306b
cmpq $0x0, -0x20(%rbp)
je 0x130c7
movq -0x10(%rbp), %rdi
callq 0x145b0
cmpq $0x0, -0x18(%rbp)
je 0x13084
movq -0x18(%rbp), %rdi
callq 0x145b0
cmpq $0x0, -0x20(%rbp)
je 0x13094
movq -0x20(%rbp), %rdi
callq 0x145b0
movq 0x11f35(%rip), %rdi     # 0x24fd0
leaq 0x63d8(%rip), %rsi      # 0x1947a
callq 0x4200
movq %rax, %rdi
movq 0x11f0f(%rip), %rsi     # 0x24fc0
callq 0x4230
movq %rax, %rdi
movq 0x11f00(%rip), %rsi     # 0x24fc0
callq 0x4230
jmp 0x130f8
movq 0x11f02(%rip), %rdi     # 0x24fd0
leaq 0x63ca(%rip), %rsi      # 0x1949f
callq 0x4200
movq %rax, %rdi
movq 0x11edc(%rip), %rsi     # 0x24fc0
callq 0x4230
movq %rax, %rdi
movq 0x11ecd(%rip), %rsi     # 0x24fc0
callq 0x4230
addq $0x50, %rsp
popq %rbp
retq
nop