// File: /workspace/github_cpp_makefile_star2_O1/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 $0xc8, %rsp
movq %r9, -0x48(%rbp)
movq %r8, %r14
movq %rcx, %r15
movq %rdx, -0x30(%rbp)
movq %rdi, -0x40(%rbp)
movslq %r14d, %rcx
movq (%r15), %rax
movq %rcx, -0x90(%rbp)
leaq (,%rcx,8), %rcx
leaq (%rcx,%rcx,2), %r12
movq %r8, %r13
sarq $0x20, %r13
movq (%rax,%r12), %rcx
leaq (,%r13,8), %rdx
leaq (%rdx,%rdx,4), %rbx
movb $0x1, 0x1(%rcx,%rbx)
movq %rsi, -0x38(%rbp)
leaq 0x28(%rsi), %rdi
movq (%rax,%r12), %rsi
addq %rbx, %rsi
callq 0x14124
movq (%r15), %rax
movq (%rax,%r12), %rcx
cmpb $0x1, (%rcx,%rbx)
jne 0x12e8a
movq -0x38(%rbp), %rcx
movb $0x1, 0x50(%rcx)
movabsq $0x100000000, %rdx      # imm = 0x100000000
cmpl $0x1, %r14d
movq -0x48(%rbp), %rbx
jg 0x12ec6
movq %r14, %rcx
shlq $0x20, %rcx
addq %rdx, %rcx
sarq $0x20, %rcx
leaq (%rcx,%rcx,2), %rdx
movq (%rax,%rdx,8), %rsi
leaq (,%r13,4), %rcx
addq %r13, %rcx
cmpb $0x0, 0x1(%rsi,%rcx,8)
je 0x12ecd
xorl %eax, %eax
xorl %r12d, %r12d
jmp 0x12f12
leaq (%rax,%rdx,8), %rax
movq (%rax), %rax
leaq -0xd8(%rbp), %rdx
movq %rdx, -0x10(%rdx)
movq 0x8(%rax,%rcx,8), %rsi
movq 0x10(%rax,%rcx,8), %rdx
addq %rsi, %rdx
leaq -0xe8(%rbp), %r12
movq %r12, %rdi
callq 0x9da8
leaq 0x58b0(%rip), %rsi      # 0x187b2
movq %r12, %rdi
callq 0x30b0
testl %eax, %eax
sete %r12b
movb $0x1, %al
testb %al, %al
je 0x12f2b
leaq -0xd8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x12f2b
callq 0x3200
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
testb %r12b, %r12b
je 0x12f66
leal 0x1(%r14), %r8d
movq %rax, %rcx
movq %r14, %rax
andq %rcx, %rax
orq %rax, %r8
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq %r15, %rcx
movq %rbx, %r9
callq 0x12e06
jmp 0x1305b
cmpl $0x2, %r14d
jl 0x1305b
movq -0x30(%rbp), %rax
movq 0xb8(%rax), %rax
testq %rax, %rax
je 0x1305b
movq (%rbx), %rcx
movq 0x8(%rbx), %rsi
movq %rsi, %rdx
subq %rcx, %rdx
je 0x12fc8
sarq $0x3, %rdx
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorl %edi, %edi
movl $0x1, %r8d
xorl %r9d, %r9d
cmpq %rax, (%rcx,%rdi,8)
movzbl %r9b, %r9d
cmovel %r8d, %r9d
incq %rdi
cmpq %rdi, %rdx
jne 0x12faa
testb $0x1, %r9b
jne 0x1305b
movq %rax, -0x88(%rbp)
cmpq 0x10(%rbx), %rsi
je 0x12fdf
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x12fee
leaq -0x88(%rbp), %rdx
movq %rbx, %rdi
callq 0x14a62
movl $0xd0, %esi
movq -0x30(%rbp), %r12
addq 0xb8(%r12), %rsi
leaq -0x88(%rbp), %rdi
callq 0x8e08
movq 0xb8(%r12), %rdx
movabsq $0x100000000, %rax      # imm = 0x100000000
leal (%rax,%r14), %r8d
addl $-0x2, %r8d
movq %r14, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
orq %rax, %r8
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x88(%rbp), %rcx
movq %rbx, %r9
callq 0x12e06
leaq -0x88(%rbp), %rdi
callq 0x14176
testl %r14d, %r14d
jle 0x13081
leal -0x1(%r14), %edx
movq (%r15), %rcx
leaq (%rdx,%rdx,2), %rax
movq (%rcx,%rax,8), %rsi
leaq (,%r13,4), %rax
addq %r13, %rax
cmpb $0x0, 0x1(%rsi,%rax,8)
je 0x13088
xorl %eax, %eax
xorl %r12d, %r12d
jmp 0x130ce
movslq %edx, %rdx
leaq (%rdx,%rdx,2), %rdx
movq (%rcx,%rdx,8), %rcx
leaq -0x78(%rbp), %rdx
movq %rdx, -0x10(%rdx)
movq 0x8(%rcx,%rax,8), %rsi
movq 0x10(%rcx,%rax,8), %rdx
addq %rsi, %rdx
leaq -0x88(%rbp), %r12
movq %r12, %rdi
callq 0x9da8
leaq 0x56f4(%rip), %rsi      # 0x187b2
movq %r12, %rdi
callq 0x30b0
testl %eax, %eax
sete %r12b
movb $0x1, %al
movabsq $0x100000000, %r13      # imm = 0x100000000
testb %al, %al
je 0x130ee
leaq -0x78(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x130ee
callq 0x3200
testb %r12b, %r12b
je 0x13129
leal (%r14,%r13), %r8d
decl %r8d
movq %r14, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
orq %rax, %r8
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq %r15, %rcx
movq %rbx, %r9
callq 0x12e06
jmp 0x1320c
testl %r14d, %r14d
jg 0x1320c
movq -0x30(%rbp), %rax
movq 0xb0(%rax), %rax
testq %rax, %rax
je 0x1320c
movq (%rbx), %rcx
movq 0x8(%rbx), %rsi
movq %rsi, %rdx
subq %rcx, %rdx
je 0x1318a
sarq $0x3, %rdx
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorl %edi, %edi
movl $0x1, %r8d
xorl %r9d, %r9d
cmpq %rax, (%rcx,%rdi,8)
movzbl %r9b, %r9d
cmovel %r8d, %r9d
incq %rdi
cmpq %rdi, %rdx
jne 0x1316c
testb $0x1, %r9b
jne 0x1320c
movq %rax, -0xb0(%rbp)
cmpq 0x10(%rbx), %rsi
je 0x131a1
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x131b0
leaq -0xb0(%rbp), %rdx
movq %rbx, %rdi
callq 0x14a62
movl $0xd0, %esi
movq -0x30(%rbp), %r13
addq 0xb0(%r13), %rsi
leaq -0xb0(%rbp), %r12
movq %r12, %rdi
callq 0x8e08
movq 0xb0(%r13), %rdx
leal 0x2(%r14), %r8d
movq %r14, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
orq %rax, %r8
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %r12, %rcx
movq %rbx, %r9
callq 0x12e06
leaq -0xb0(%rbp), %rdi
callq 0x14176
movq %r14, %r13
shrq $0x20, %r13
movq -0x90(%rbp), %rax
leaq (%rax,%rax,2), %rbx
cmpl $0x1, %r13d
jg 0x13247
movq (%r15), %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
addq %r14, %rcx
sarq $0x20, %rcx
movq (%rax,%rbx,8), %rdx
leaq (%rcx,%rcx,4), %rcx
cmpb $0x0, 0x1(%rdx,%rcx,8)
je 0x1324e
xorl %eax, %eax
xorl %r12d, %r12d
jmp 0x13293
leaq (%rax,%rbx,8), %rax
movq (%rax), %rax
leaq -0xa0(%rbp), %rdx
movq %rdx, -0x10(%rdx)
movq 0x8(%rax,%rcx,8), %rsi
movq 0x10(%rax,%rcx,8), %rdx
addq %rsi, %rdx
leaq -0xb0(%rbp), %r12
movq %r12, %rdi
callq 0x9da8
leaq 0x552f(%rip), %rsi      # 0x187b2
movq %r12, %rdi
callq 0x30b0
testl %eax, %eax
sete %r12b
movb $0x1, %al
testb %al, %al
je 0x132ac
leaq -0xa0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x132ac
callq 0x3200
testb %r12b, %r12b
je 0x132f1
movq %r14, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
addq %rcx, %rax
movl %r14d, %r8d
orq %rax, %r8
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq %r15, %rcx
movq -0x48(%rbp), %r9
callq 0x12e06
jmp 0x133db
cmpl $0x2, %r13d
jl 0x133db
movq -0x30(%rbp), %rax
movq 0xc8(%rax), %rax
testq %rax, %rax
je 0x133db
movq -0x48(%rbp), %rdx
movq (%rdx), %rcx
movq 0x8(%rdx), %rsi
movq %rsi, %rdx
subq %rcx, %rdx
je 0x13357
sarq $0x3, %rdx
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorl %edi, %edi
movl $0x1, %r8d
xorl %r9d, %r9d
cmpq %rax, (%rcx,%rdi,8)
movzbl %r9b, %r9d
cmovel %r8d, %r9d
incq %rdi
cmpq %rdi, %rdx
jne 0x13339
testb $0x1, %r9b
jne 0x133db
movq %rax, -0x68(%rbp)
movq -0x48(%rbp), %rdi
cmpq 0x10(%rdi), %rsi
je 0x1336f
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x13378
leaq -0x68(%rbp), %rdx
callq 0x14a62
movl $0xd0, %esi
movq -0x30(%rbp), %r12
addq 0xc8(%r12), %rsi
leaq -0x68(%rbp), %rdi
callq 0x8e08
movq 0xc8(%r12), %rdx
movq %r14, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
movl %r14d, %ecx
addq %rax, %rcx
movabsq $-0x200000000, %r8      # imm = 0xFFFFFFFE00000000
addq %rcx, %r8
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x68(%rbp), %rcx
movq -0x48(%rbp), %r9
callq 0x12e06
leaq -0x68(%rbp), %rdi
callq 0x14176
testl %r13d, %r13d
jle 0x13403
movq (%r15), %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %r14, %rcx
sarq $0x20, %rcx
movq (%rax,%rbx,8), %rdx
leaq (%rcx,%rcx,4), %rcx
cmpb $0x0, 0x1(%rdx,%rcx,8)
je 0x13409
xorl %eax, %eax
xorl %ebx, %ebx
jmp 0x13447
leaq (%rax,%rbx,8), %rax
movq (%rax), %rax
leaq -0x58(%rbp), %rdx
movq %rdx, -0x10(%rdx)
movq 0x8(%rax,%rcx,8), %rsi
movq 0x10(%rax,%rcx,8), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %r12
movq %r12, %rdi
callq 0x9da8
leaq 0x537a(%rip), %rsi      # 0x187b2
movq %r12, %rdi
callq 0x30b0
testl %eax, %eax
sete %bl
movb $0x1, %al
testb %al, %al
je 0x1345d
leaq -0x58(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1345d
callq 0x3200
testb %bl, %bl
je 0x13497
movq %r14, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
addq %rcx, %rax
movl %r14d, %r8d
orq %rax, %r8
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq %r15, %rcx
movq -0x48(%rbp), %r9
callq 0x12e06
jmp 0x13589
testl %r13d, %r13d
movq -0x48(%rbp), %rbx
jg 0x13589
movq -0x30(%rbp), %rax
movq 0xc0(%rax), %rax
testq %rax, %rax
je 0x13589
movq (%rbx), %rcx
movq 0x8(%rbx), %rsi
movq %rsi, %rdx
subq %rcx, %rdx
je 0x134fc
sarq $0x3, %rdx
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorl %edi, %edi
movl $0x1, %r8d
xorl %r9d, %r9d
cmpq %rax, (%rcx,%rdi,8)
movzbl %r9b, %r9d
cmovel %r8d, %r9d
incq %rdi
cmpq %rdi, %rdx
jne 0x134de
testb $0x1, %r9b
jne 0x13589
movq %rax, -0xc8(%rbp)
cmpq 0x10(%rbx), %rsi
je 0x13513
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x13522
leaq -0xc8(%rbp), %rdx
movq %rbx, %rdi
callq 0x14a62
movl $0xd0, %esi
movq -0x30(%rbp), %r12
addq 0xc0(%r12), %rsi
leaq -0xc8(%rbp), %r15
movq %r15, %rdi
callq 0x8e08
movq 0xc0(%r12), %rdx
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %r14, %rcx
movl %r14d, %eax
addq %rcx, %rax
movabsq $0x200000000, %r8       # imm = 0x200000000
addq %rax, %r8
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %r15, %rcx
movq %rbx, %r9
callq 0x12e06
leaq -0xc8(%rbp), %rdi
callq 0x14176
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0xc8(%rbp), %rdi
jmp 0x135c6
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
jmp 0x135c6
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
jmp 0x135c6
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x14176
movq %rbx, %rdi
callq 0x33f0
nop