// File: /workspace/github_cpp_makefile_star2_O2/Doug0855[P]TigerZone/Board.cpp
// Function: Board::buildLake(Structure*, Tile*, std::vector<std::vector<Block, std::allocator<Block>>, std::allocator<std::vector<Block, std::allocator<Block>>>>&, std::pair<int, int>, std::vector<Tile*, std::allocator<Tile*>>&)
void Board::buildLake(Structure* struc, Tile *tile, std::vector< std::vector<Block> >& tileBlocks, std::pair<int,int> blockSpot, std::vector<Tile*> &visitedTiles) {
	// std::cout<<"in build lake"<<std::endl;
	int row = blockSpot.first;
	int col = blockSpot.second;
	tileBlocks[row][col].visit();
	// for(int i = 0; i < 3; i++) {
	// 	for(int j = 0; j < 3; j++) {
	// 		std::cout<<"Block at "<<i<<' '<<j<<" for tile "<<tile<<" has been visited? "<<tileBlocks[i][j].isVisited()<<std::endl;
	// 	}
	// }

	// Push the current block into the vector of blocks for this structure
	struc->structureBlocks.push_back(tileBlocks[row][col]);

	// check block for meeple and set the structure boolean accordingly
	if(tileBlocks[row][col].hasMeeple())
		struc->hasMeeple = true;

	// Check to see if you've already added this tiles animals to the structure
	bool addedTileAnimals;
	for(int i = 0; i < visitedTiles.size(); i++) {
			if(visitedTiles[i] == tile)
			{
				addedTileAnimals = true;
				//debugging std::cout<<"Added animals already for this tile"<<std::endl;
			}
	}
	// If you havent already added the tiles animals to the structure, do so
	if(!addedTileAnimals) {
		struc->checkAnimals(tile);
		// if(tile->hasCrocodile())
		// 	struc->crocodileCount++;
		// if(tile->hasDeer())
		// 	struc->deerCount++;
		// if(tile->hasBoar())
		// 	struc->boarCount++;
		// if(tile->hasBuffalo())
		// 	struc->buffaloCount++;
	}

	// Check tiles above, below, left, and right of the current block to see if lake structure continues. 
	// Call this function with the new coordinates (of the direction you're going) again if it does
	if((row + 1) <= 2 && !(tileBlocks[row + 1][col].isVisited()) && tileBlocks[row+1][col].getType() == "lake") {
		buildLake(struc, tile, tileBlocks, std::pair<int,int>(row+1,col), visitedTiles);
	}
	else if(row + 1 > 2 && tile->getDownTile() != NULL) {
		bool visitedNeighborTile = false;
		for(int i = 0; i < visitedTiles.size(); i++) {
			if(visitedTiles[i] == tile->getDownTile())
				visitedNeighborTile = true;
		}
		if(!visitedNeighborTile) {
			visitedTiles.push_back(tile->getDownTile());
			std::vector< std::vector<Block> > newBlocks = tile->getDownTile()->getInnerBlocks();
			buildLake(struc, tile->getDownTile(), newBlocks, std::pair<int,int>(row-2,col), visitedTiles);
		}
	}
	// std::cout<<"about to check row-1"<<std::endl;
	if((row - 1) >= 0 && !(tileBlocks[row - 1][col].isVisited()) && tileBlocks[row - 1][col].getType() == "lake") {
		buildLake(struc, tile, tileBlocks, std::pair<int,int>(row-1,col), visitedTiles);
	}
	else if(row-1 < 0 && tile->getUpTile() != NULL) {
		bool visitedNeighborTile = false;
		for(int i = 0; i < visitedTiles.size(); i++) {
			if(visitedTiles[i] == tile->getUpTile())
				visitedNeighborTile = true;
		}
		if(!visitedNeighborTile) {
			visitedTiles.push_back(tile->getUpTile());
			std::vector< std::vector<Block> > newBlocks = tile->getUpTile()->getInnerBlocks();
			buildLake(struc, tile->getUpTile(), newBlocks, std::pair<int,int>(row+2,col), visitedTiles);
		}
	}
	// std::cout<<"about to check col+1"<<std::endl;
	if((col + 1) <= 2 && !(tileBlocks[row][col + 1].isVisited()) && tileBlocks[row][col + 1].getType() == "lake") {
		buildLake(struc, tile, tileBlocks, std::pair<int,int>(row,col+1), visitedTiles);
	}
	else if(col+1 > 2 && tile->getRightTile() != NULL) {
		bool visitedNeighborTile = false;
		for(int i = 0; i < visitedTiles.size(); i++) {
			if(visitedTiles[i] == tile->getRightTile())
				visitedNeighborTile = true;
		}
		if(!visitedNeighborTile) {
			visitedTiles.push_back(tile->getRightTile());
			std::vector< std::vector<Block> > newBlocks = tile->getRightTile()->getInnerBlocks();
			buildLake(struc, tile->getRightTile(), newBlocks, std::pair<int,int>(row,col-2), visitedTiles);
		}
	}
	// std::cout<<"about to check col-1"<<std::endl;
	if((col - 1) >= 0 && !(tileBlocks[row][col-1].isVisited()) && tileBlocks[row][col - 1].getType() == "lake") {
		// std::cout<<"passing col-1"<<std::endl;
		buildLake(struc, tile, tileBlocks, std::pair<int,int>(row,col-1), visitedTiles);
	}
	else if(col-1 < 0 && tile->getLeftTile() != NULL) {
		bool visitedNeighborTile = false;
		for(int i = 0; i < visitedTiles.size(); i++) {
			if(visitedTiles[i] == tile->getLeftTile())
				visitedNeighborTile = true;
		}
		if(!visitedNeighborTile) {
			visitedTiles.push_back(tile->getLeftTile());
			std::vector< std::vector<Block> > newBlocks = tile->getLeftTile()->getInnerBlocks();
			buildLake(struc, tile->getLeftTile(), newBlocks, std::pair<int,int>(row,col+2), visitedTiles);
		}
	}
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, -0x70(%rbp)
movq %rcx, %r15
movq %rdx, %r13
movq %rsi, %rdx
movq %rdi, -0x38(%rbp)
movslq %r8d, %rax
movq (%rcx), %rcx
imulq $0x18, %rax, %r12
movq %r8, %r14
movq %r8, %rax
sarq $0x20, %rax
movq (%rcx,%r12), %rsi
imulq $0x28, %rax, %rbx
movb $0x1, 0x1(%rsi,%rbx)
addq %rbx, %rsi
movq %rdx, -0x30(%rbp)
leaq 0x28(%rdx), %rdi
callq 0xec76
movq %r15, -0x48(%rbp)
movq (%r15), %rcx
movq %r12, %r15
movq (%rcx,%r12), %rax
cmpb $0x1, (%rax,%rbx)
jne 0xdd65
movq -0x30(%rbp), %rax
movb $0x1, 0x50(%rax)
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
cmpl $0x1, %r14d
movq %r13, %rdx
movq %r13, -0x40(%rbp)
jg 0xde2b
movq %r14, %rax
shlq $0x20, %rax
addq %r9, %rax
incq %rax
sarq $0x20, %rax
imulq $0x18, %rax, %rax
movq (%rcx,%rax), %rax
cmpb $0x0, 0x1(%rax,%rbx)
movq -0x70(%rbp), %r12
movq %r14, %r13
jne 0xdee5
leaq (%rax,%rbx), %rsi
addq $0x8, %rsi
leaq -0x68(%rbp), %r14
movq %r14, %rdi
callq 0x32c0
leaq 0x4970(%rip), %rsi      # 0x12732
movq %r14, %rdi
callq 0x6261
movq %r15, %r14
movq %r12, %r15
movl %eax, %r12d
leaq -0x68(%rbp), %rdi
callq 0x3120
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
testb %r12b, %r12b
movq %r15, %r12
movq %r14, %r15
movq -0x40(%rbp), %rdx
je 0xdee5
leal 0x1(%r13), %r8d
movq %r13, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
orq %rax, %r8
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x48(%rbp), %rcx
movq %r12, %r9
movq %rdx, %r14
callq 0xdcf6
movq %r14, %rdx
jmp 0xdedf
movq 0xb8(%rdx), %rax
testq %rax, %rax
movq -0x70(%rbp), %r12
movq %r14, %r13
je 0xdef5
movq (%r12), %rcx
movq 0x8(%r12), %r10
subq %rcx, %r10
sarq $0x3, %r10
xorl %esi, %esi
xorl %edi, %edi
cmpq %rsi, %r10
je 0xde6b
cmpq %rax, (%rcx,%rsi,8)
sete %r8b
orb %r8b, %dil
incq %rsi
jmp 0xde56
testb $0x1, %dil
jne 0xdee5
leaq -0x68(%rbp), %rsi
movq %rax, (%rsi)
movq %r12, %rdi
movq %rdx, %r14
callq 0xf488
movl $0xd0, %esi
addq 0xb8(%r14), %rsi
leaq -0x68(%rbp), %rdi
callq 0x65ba
movq 0xb8(%r14), %rdx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
leal (%rax,%r13), %r8d
decl %r8d
movq %r13, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
orq %rax, %r8
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq -0x68(%rbp), %rcx
movq %r12, %r9
callq 0xdcf6
leaq -0x68(%rbp), %rdi
callq 0xecb2
movq -0x40(%rbp), %rdx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
testl %r13d, %r13d
jle 0xdf8c
movq -0x48(%rbp), %rax
movq (%rax), %rcx
leal (%r9,%r13), %eax
imulq $0x18, %rax, %rax
movq (%rcx,%rax), %rax
cmpb $0x0, 0x1(%rax,%rbx)
jne 0xe039
leaq (%rax,%rbx), %rsi
addq $0x8, %rsi
leaq -0x68(%rbp), %r14
movq %r14, %rdi
callq 0x32c0
leaq 0x480b(%rip), %rsi      # 0x12732
movq %r14, %rdi
callq 0x6261
movq %r12, %rbx
movl %eax, %r12d
movq %r14, %rdi
movq -0x40(%rbp), %r14
callq 0x3120
movq %r14, %rdx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
testb %r12b, %r12b
movq %rbx, %r12
je 0xe039
leal (%r9,%r13), %r8d
movq %r13, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
orq %rax, %r8
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x48(%rbp), %rcx
movq %r12, %r9
movq %rdx, %rbx
callq 0xdcf6
movq %rbx, %rdx
jmp 0xe033
movq 0xb0(%rdx), %rax
testq %rax, %rax
je 0xe039
movq (%r12), %rcx
movq 0x8(%r12), %r10
subq %rcx, %r10
sarq $0x3, %r10
xorl %esi, %esi
xorl %edi, %edi
cmpq %rsi, %r10
je 0xdfc5
cmpq %rax, (%rcx,%rsi,8)
sete %r8b
orb %r8b, %dil
incq %rsi
jmp 0xdfb0
testb $0x1, %dil
jne 0xe039
leaq -0x68(%rbp), %rsi
movq %rax, (%rsi)
movq %r12, %rdi
movq %rdx, %rbx
callq 0xf488
movl $0xd0, %esi
addq 0xb0(%rbx), %rsi
leaq -0x68(%rbp), %r14
movq %r14, %rdi
callq 0x65ba
movq 0xb0(%rbx), %rdx
leal 0x2(%r13), %r8d
movq %r13, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
orq %rax, %r8
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq %r14, %rcx
movq %r12, %r9
callq 0xdcf6
leaq -0x68(%rbp), %rdi
callq 0xecb2
movq -0x40(%rbp), %rdx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movq %r13, %rbx
shrq $0x20, %rbx
cmpl $0x1, %ebx
jg 0xe0f8
movq -0x48(%rbp), %rax
movq (%rax), %rax
leaq (%r9,%r13), %rcx
incq %rcx
sarq $0x20, %rcx
movq (%rax,%r15), %rax
imulq $0x28, %rcx, %rcx
cmpb $0x0, 0x1(%rax,%rcx)
jne 0xe1af
leaq (%rax,%rcx), %rsi
addq $0x8, %rsi
leaq -0x68(%rbp), %r14
movq %r14, %rdi
callq 0x32c0
leaq 0x46a9(%rip), %rsi      # 0x12732
movq %r14, %rdi
callq 0x6261
movq %r15, %r14
movq %r12, %r15
movl %eax, %r12d
leaq -0x68(%rbp), %rdi
callq 0x3120
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
testb %r12b, %r12b
movq %r15, %r12
movq %r14, %r15
movq -0x40(%rbp), %rdx
je 0xe1af
movq %r13, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
addq %r9, %rax
movl %r13d, %ecx
leaq (%rcx,%rax), %r8
incq %r8
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x48(%rbp), %rcx
movq %r12, %r9
movq %rdx, %r14
callq 0xdcf6
movq %r14, %rdx
jmp 0xe1a9
movq 0xc8(%rdx), %rax
testq %rax, %rax
je 0xe1b7
movq (%r12), %rcx
movq 0x8(%r12), %r10
subq %rcx, %r10
sarq $0x3, %r10
xorl %esi, %esi
xorl %edi, %edi
cmpq %rsi, %r10
je 0xe131
cmpq %rax, (%rcx,%rsi,8)
sete %r8b
orb %r8b, %dil
incq %rsi
jmp 0xe11c
testb $0x1, %dil
jne 0xe1af
leaq -0x68(%rbp), %rsi
movq %rax, (%rsi)
movq %r12, %rdi
movq %rdx, %r14
callq 0xf488
movl $0xd0, %esi
addq 0xc8(%r14), %rsi
leaq -0x68(%rbp), %rdi
callq 0x65ba
movq 0xc8(%r14), %rdx
movq %r13, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
movl %r13d, %ecx
addq %rax, %rcx
movabsq $-0x200000000, %r8      # imm = 0xFFFFFFFE00000000
addq %rcx, %r8
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq -0x68(%rbp), %rcx
movq %r12, %r9
callq 0xdcf6
leaq -0x68(%rbp), %rdi
callq 0xecb2
movq -0x40(%rbp), %rdx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
testl %ebx, %ebx
jle 0xe247
movq -0x48(%rbp), %rax
movq (%rax), %rax
addl %r9d, %ebx
movq (%rax,%r15), %rax
imulq $0x28, %rbx, %rcx
cmpb $0x0, 0x1(%rax,%rcx)
jne 0xe2f3
leaq (%rax,%rcx), %rsi
addq $0x8, %rsi
leaq -0x68(%rbp), %r14
movq %r14, %rdi
callq 0x32c0
leaq 0x4543(%rip), %rsi      # 0x12732
movq %r14, %rdi
callq 0x6261
movq %r12, %rbx
movl %eax, %r12d
movq %r14, %rdi
movq -0x40(%rbp), %r14
callq 0x3120
testb %r12b, %r12b
je 0xe2f3
movq %rbx, %r9
movq %r13, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
addq %rcx, %rax
movl %r13d, %r8d
orq %rax, %r8
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq %r14, %rdx
movq -0x48(%rbp), %rcx
callq 0xdcf6
jmp 0xe2f3
movq 0xc0(%rdx), %rax
testq %rax, %rax
je 0xe2f3
movq (%r12), %rcx
movq 0x8(%r12), %r9
subq %rcx, %r9
sarq $0x3, %r9
xorl %esi, %esi
xorl %edi, %edi
cmpq %rsi, %r9
je 0xe280
cmpq %rax, (%rcx,%rsi,8)
sete %r8b
orb %r8b, %dil
incq %rsi
jmp 0xe26b
testb $0x1, %dil
jne 0xe2f3
leaq -0x68(%rbp), %rsi
movq %rax, (%rsi)
movq %r12, %rdi
movq %rdx, %rbx
callq 0xf488
movl $0xd0, %esi
addq 0xc0(%rbx), %rsi
leaq -0x68(%rbp), %r14
movq %r14, %rdi
callq 0x65ba
movq 0xc0(%rbx), %rdx
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %r13, %rcx
movl %r13d, %eax
addq %rcx, %rax
movabsq $0x200000000, %r8       # imm = 0x200000000
addq %rax, %r8
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq %r14, %rcx
movq %r12, %r9
callq 0xdcf6
leaq -0x68(%rbp), %rdi
callq 0xecb2
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xe308
jmp 0xe308
jmp 0xe308
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0xecb2
movq %rbx, %rdi
callq 0x33c0