// File: /workspace/github_cpp_makefile_star2_O2/MatthewZMD[P]TetrisDual/concreteboard.cc
// Function: ConcreteBoard::drop()
int ConcreteBoard::drop() {
	// down until impossible
	while (down(1));
    // Consider level4 case
	if (level->dropBrownBlock()) {
        ++countTurn;
        if (countTurn == 5) {
			for (int i = 17; i >= 0; --i) {
				if (allCells[i][5].type == CellType::E) {
                    allCells[i][5].type = CellType::Star;
                    break;
                }
            }
			countTurn = 0;
        }
    }
	bool lineFull = 1;
	int RemoveLine = 0;
	for (int i = 17; i >= 0; --i) {
		for (int j = 0; j < 11; ++j) {
			if (allCells[i][j].isEmpty()) {
				lineFull = 0;
				break;
			}
		}
		if (lineFull == 1) {
			for (int j = 0; j < 11; ++j) {
				allCells[i][j].cellState.cellStatus = CellStatus::Dead;
				if (allCells[i][j].squad.size() == 0 && allCells[i][j].type != CellType::Star) {
					score += (allCells[i][j].blockLevel + 1) * (allCells[i][j].blockLevel + 1);
				}
				allCells[i][j].type = CellType::E;
				for (auto &k : allCells[i][j].squad) {
					for (unsigned p = 0; p < k->squad.size(); ++p) {
						if (k->squad[p]->pos == allCells[i][j].pos) {
							k->squad.erase(k->squad.begin() + p);
							break;
						}
					}
				}
				allCells[i][j].notifyObservers();
			}
			++RemoveLine;
			++i;
		}
		lineFull = 1;
	}
	if (RemoveLine != 0) {
		score += (RemoveLine + level->getLevel()) * (RemoveLine + level->getLevel());
		countTurn = 0;

	}
	for (int j = 0; j < 11; ++j) {
		if (!allCells[2][j].isEmpty()) {
			throw "Game Over";
		}
	}
	turnGG = true;
	notifyObservers();
	return RemoveLine;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
pushq $0x1
popq %rbp
movq (%rbx), %rax
movq %rbx, %rdi
movl %ebp, %esi
callq *0x20(%rax)
testb %al, %al
jne 0x8dec
movq 0x60(%rbx), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
testb %al, %al
je 0x8e44
movl 0x70(%rbx), %eax
incl %eax
movl %eax, 0x70(%rbx)
cmpl $0x5, %eax
jne 0x8e44
movq 0x78(%rbx), %rax
pushq $0x11
popq %rcx
testl %ecx, %ecx
js 0x8e40
movl %ecx, %edx
imulq $0x18, %rdx, %rdx
movq (%rax,%rdx), %rdx
decl %ecx
cmpl $0x7, 0x334(%rdx)
jne 0x8e1d
movl $0x8, 0x334(%rdx)
andl $0x0, 0x70(%rbx)
pushq $0x11
popq %rax
movl $0x0, 0x4(%rsp)
movl %eax, %eax
imulq $0x18, %rax, %r12
movq %rax, 0x8(%rsp)
testl %eax, %eax
js 0x8f7c
xorl %edi, %edi
leaq 0x90(%rdi), %r14
cmpq $0x6c0, %r14            # imm = 0x6C0
je 0x8e8d
movq 0x78(%rbx), %rax
addq (%rax,%r12), %rdi
callq 0x7fde
movq %r14, %rdi
testb %al, %al
je 0x8e64
jmp 0x8f70
xorl %edx, %edx
cmpq $0xb, %rdx
je 0x8f62
movq 0x78(%rbx), %rax
movq (%rax,%r12), %rcx
movq %rdx, 0x10(%rsp)
imulq $0x90, %rdx, %rbp
andl $0x0, 0x88(%rcx,%rbp)
leaq (%rcx,%rbp), %rax
movq 0x68(%rcx,%rbp), %r15
movq 0x70(%rcx,%rbp), %r13
cmpq %r15, %r13
jne 0x8ed9
cmpl $0x8, 0x64(%rax)
je 0x8ed9
movl 0x60(%rax), %ecx
incl %ecx
imull %ecx, %ecx
addl %ecx, 0x5c(%rbx)
movl $0x7, 0x64(%rax)
cmpq %r13, %r15
je 0x8f40
xorl %ecx, %ecx
movl %ecx, %r14d
movq (%r15), %rcx
movq 0x68(%rcx), %rax
movq 0x70(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r14, %rcx
jbe 0x8f3a
movq (%rax,%r14,8), %rdi
addq $0x58, %rdi
movq 0x78(%rbx), %rax
movq (%rax,%r12), %rax
movq 0x58(%rax,%rbp), %rsi
callq 0xadf8
leal 0x1(%r14), %ecx
testb %al, %al
je 0x8ee7
movq (%r15), %rdi
shlq $0x3, %r14
addq 0x68(%rdi), %r14
addq $0x68, %rdi
movq %r14, %rsi
callq 0x99f6
addq $0x8, %r15
jmp 0x8ee0
movq 0x78(%rbx), %rax
movq (%rax,%r12), %rax
leaq (%rax,%rbp), %rdi
addq $0x8, %rdi
callq 0xda72
movq 0x10(%rsp), %rdx
incq %rdx
jmp 0x8e8f
incl 0x4(%rsp)
movq 0x8(%rsp), %rax
jmp 0x8e5a
movq 0x8(%rsp), %rax
decl %eax
jmp 0x8e4f
movl 0x4(%rsp), %ebp
testl %ebp, %ebp
je 0x8fa9
movq 0x60(%rbx), %rdi
callq 0xd862
movl %eax, %r14d
addl %ebp, %r14d
movq 0x60(%rbx), %rdi
callq 0xd862
addl %ebp, %eax
imull %r14d, %eax
addl %eax, 0x5c(%rbx)
andl $0x0, 0x70(%rbx)
xorl %edi, %edi
leaq 0x90(%rdi), %r14
cmpq $0x6c0, %r14            # imm = 0x6C0
je 0x8ff2
movq 0x78(%rbx), %rax
addq 0x30(%rax), %rdi
callq 0x7fde
movq %r14, %rdi
testb %al, %al
jne 0x8fab
pushq $0x8
popq %rdi
callq 0x5170
leaq 0x8359(%rip), %rcx      # 0x11337
movq %rcx, (%rax)
movq 0x12fa8(%rip), %rsi     # 0x1bf90
movq %rax, %rdi
xorl %edx, %edx
callq 0x5490
movb $0x1, 0x90(%rbx)
movq %rbx, %rdi
callq 0xda72
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq