I'm working on a tetris clone and everything is practically done but I've encountered a bug that I have no idea how to fix. I have spent several days on it to no avail.
What happens is that after playing for a while a piece will land and fill up all the squares above it all the way to the top. You can see what I mean in this picture:
I have narrowed down the issue to these lines:
for row in range(4):
for col in range(4):
if array[row][col] != 0:
setDead(row+self.block.pos[0], col+self.block.pos[1],
array[row][col])
setDead(row,col,val)
sets array[row][col] = val
in a 2-d array I have.
Before these lines everything is normal, but after these lines the extra squares are added. What these lines are supposed to be doing is copying from the block array to the board.
I would be very appreciative of some help as I have said, I have spent several hours on this.
def setDead(row, col, val):
global dead_blocks
dead_blocks[row][col] = val
dead_blocks is the 2-d array where I store all the dead blocks
Here is some console output, these are print statements before dead_blocks[row][col] = val
and after. It looks like on the first assignment it is setting all the blocks above it in the column to the same value.
As you can see only dead_blocks[8][3]
should be set to 2
but instead the squares from dead_blocks[8][3]
to dead_blocks[0][3]
are all being set to 2
.