// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
movq (%rdi), %rax
movl $0x1, %esi
callq *0x20(%rax)
testb $0x1, %al
jne 0x124bc
jmp 0x124be
jmp 0x124a7
movq -0x80(%rbp), %rdi
addq $0x60, %rdi
callq 0x13b10
movq %rax, %rdi
movq (%rdi), %rax
callq *0x20(%rax)
testb $0x1, %al
jne 0x124dd
jmp 0x12562
movq -0x80(%rbp), %rax
movl 0x70(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x70(%rax)
cmpl $0x5, 0x70(%rax)
jne 0x12560
movl $0x11, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jl 0x12555
movq -0x80(%rbp), %rdi
addq $0x78, %rdi
movslq -0xc(%rbp), %rsi
callq 0x13d50
movq %rax, %rdi
movl $0x5, %esi
callq 0x13d70
cmpl $0x7, 0x64(%rax)
jne 0x12548
movq -0x80(%rbp), %rdi
addq $0x78, %rdi
movslq -0xc(%rbp), %rsi
callq 0x13d50
movq %rax, %rdi
movl $0x5, %esi
callq 0x13d70
movl $0x8, 0x64(%rax)
jmp 0x12555
jmp 0x1254a
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x124f7
movq -0x80(%rbp), %rax
movl $0x0, 0x70(%rax)
jmp 0x12562
movb $0x1, -0xd(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x11, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jl 0x128b8
movl $0x0, -0x1c(%rbp)
cmpl $0xb, -0x1c(%rbp)
jge 0x125c9
movq -0x80(%rbp), %rdi
addq $0x78, %rdi
movslq -0x18(%rbp), %rsi
callq 0x13d50
movq %rax, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x13d70
movq %rax, %rdi
callq 0xffc0
testb $0x1, %al
jne 0x125b6
jmp 0x125bc
movb $0x0, -0xd(%rbp)
jmp 0x125c9
jmp 0x125be
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x12585
movb -0xd(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x128a6
movl $0x0, -0x20(%rbp)
cmpl $0xb, -0x20(%rbp)
jge 0x12894
movq -0x80(%rbp), %rdi
addq $0x78, %rdi
movslq -0x18(%rbp), %rsi
callq 0x13d50
movq %rax, %rdi
movslq -0x20(%rbp), %rsi
callq 0x13d70
movq -0x80(%rbp), %rdi
movl $0x0, 0x88(%rax)
addq $0x78, %rdi
movslq -0x18(%rbp), %rsi
callq 0x13d50
movq %rax, %rdi
movslq -0x20(%rbp), %rsi
callq 0x13d70
movq %rax, %rdi
addq $0x68, %rdi
callq 0xd020
cmpq $0x0, %rax
jne 0x126ca
movq -0x80(%rbp), %rdi
addq $0x78, %rdi
movslq -0x18(%rbp), %rsi
callq 0x13d50
movq %rax, %rdi
movslq -0x20(%rbp), %rsi
callq 0x13d70
cmpl $0x8, 0x64(%rax)
je 0x126ca
movq -0x80(%rbp), %rdi
addq $0x78, %rdi
movslq -0x18(%rbp), %rsi
callq 0x13d50
movq %rax, %rdi
movslq -0x20(%rbp), %rsi
callq 0x13d70
movq -0x80(%rbp), %rdi
movl 0x60(%rax), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
addq $0x78, %rdi
movslq -0x18(%rbp), %rsi
callq 0x13d50
movq %rax, %rdi
movslq -0x20(%rbp), %rsi
callq 0x13d70
movl -0x84(%rbp), %ecx
movq %rax, %rdx
movq -0x80(%rbp), %rax
movl 0x60(%rdx), %edx
addl $0x1, %edx
imull %edx, %ecx
addl 0x5c(%rax), %ecx
movl %ecx, 0x5c(%rax)
movq -0x80(%rbp), %rdi
addq $0x78, %rdi
movslq -0x18(%rbp), %rsi
callq 0x13d50
movq %rax, %rdi
movslq -0x20(%rbp), %rsi
callq 0x13d70
movq -0x80(%rbp), %rdi
movl $0x7, 0x64(%rax)
addq $0x78, %rdi
movslq -0x18(%rbp), %rsi
callq 0x13d50
movq %rax, %rdi
movslq -0x20(%rbp), %rsi
callq 0x13d70
addq $0x68, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0xd190
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0xd1c0
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xd1f0
testb $0x1, %al
jne 0x12743
jmp 0x1285d
leaq -0x30(%rbp), %rdi
callq 0xd230
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq %rax, -0x90(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rdi
addq $0x68, %rdi
callq 0xd020
movq %rax, %rcx
movq -0x90(%rbp), %rax
cmpq %rcx, %rax
jae 0x1284d
movq -0x40(%rbp), %rax
movq (%rax), %rdi
addq $0x68, %rdi
movl -0x44(%rbp), %eax
movl %eax, %esi
callq 0xd480
movq -0x80(%rbp), %rdi
movq (%rax), %rax
addq $0x58, %rax
movq %rax, -0x98(%rbp)
addq $0x78, %rdi
movslq -0x18(%rbp), %rsi
callq 0x13d50
movq %rax, %rdi
movslq -0x20(%rbp), %rsi
callq 0x13d70
movq -0x98(%rbp), %rdi
movq 0x58(%rax), %rax
movq %rax, -0x4c(%rbp)
movq -0x4c(%rbp), %rsi
callq 0x1a4f0
testb $0x1, %al
jne 0x127e2
jmp 0x1283d
movq -0x40(%rbp), %rax
movq (%rax), %rax
addq $0x68, %rax
movq %rax, -0xa0(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rdi
addq $0x68, %rdi
callq 0xd190
movq %rax, -0x68(%rbp)
movl -0x44(%rbp), %eax
movl %eax, %esi
leaq -0x68(%rbp), %rdi
callq 0x106a0
movq %rax, -0x60(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x14030
movq -0xa0(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x13fc0
movq %rax, -0x70(%rbp)
jmp 0x1284d
jmp 0x1283f
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x12757
jmp 0x1284f
leaq -0x30(%rbp), %rdi
callq 0xd2d0
jmp 0x1272d
movq -0x80(%rbp), %rdi
addq $0x78, %rdi
movslq -0x18(%rbp), %rsi
callq 0x13d50
movq %rax, %rdi
movslq -0x20(%rbp), %rsi
callq 0x13d70
movq %rax, %rdi
addq $0x8, %rdi
callq 0x25430
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x125e1
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movb $0x1, -0xd(%rbp)
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x12574
cmpl $0x0, -0x14(%rbp)
je 0x1292e
movq -0x80(%rbp), %rdi
movl -0x14(%rbp), %eax
movl %eax, -0xac(%rbp)
addq $0x60, %rdi
callq 0x13b10
movq %rax, %rdi
callq 0x24930
movq -0x80(%rbp), %rdi
movl %eax, %ecx
movl -0xac(%rbp), %eax
addl %ecx, %eax
movl %eax, -0xa4(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0xa8(%rbp)
addq $0x60, %rdi
callq 0x13b10
movq %rax, %rdi
callq 0x24930
movl -0xa8(%rbp), %edx
movl -0xa4(%rbp), %ecx
movl %eax, %esi
movq -0x80(%rbp), %rax
addl %esi, %edx
imull %edx, %ecx
addl 0x5c(%rax), %ecx
movl %ecx, 0x5c(%rax)
movl $0x0, 0x70(%rax)
movl $0x0, -0x74(%rbp)
cmpl $0xb, -0x74(%rbp)
jge 0x12999
movq -0x80(%rbp), %rdi
addq $0x78, %rdi
movl $0x2, %esi
callq 0x13d50
movq %rax, %rdi
movslq -0x74(%rbp), %rsi
callq 0x13d70
movq %rax, %rdi
callq 0xffc0
testb $0x1, %al
jne 0x1298c
movl $0x8, %edi
callq 0x61a0
movq %rax, %rdi
leaq 0x1a9c7(%rip), %rax     # 0x2d340
movq %rax, (%rdi)
movq 0x31605(%rip), %rsi     # 0x43f88
xorl %eax, %eax
movl %eax, %edx
callq 0x6600
jmp 0x1298e
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x12935
movq -0x80(%rbp), %rdi
movb $0x1, 0x90(%rdi)
callq 0x25430
movl -0x14(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)