Having trouble with a section of my coding project, anyone have some tips?

Long story short I am building a game of tetris to make sure I don’t get rusty on my python skills for next year. I plan to make it into a GUI version once I have the basic game completed.

The issue I am having is in relation to “IF” statements. For some reason the logic is getting caught in these statements and deleting itself from existence. I spent a while already narrowing it down and I have gotten it to the point where it half works, though the falling blocks end up overlapping.

The basic function of how my program works is I have two dictionaries running in parallel with the main one (self.game in the code) being cleared and overwritten by an up to date dictionary at the end. The main issue is with the first “IF” statement which should check if the block is falling and then determine if the spot directly below it is filled or not. For some reason only about half the blocks that should go through this section actually go though it with the rest disappearing.

If anyone can help I’d really appreciate it. I’ve attached a picture of the section of code that isn’t working.

Edit: self.size[x/y] are the upper bounds of the grid the game is played on

    def has_touched_down(self):
        """
        Determines if the block has touched another block or the ground
        If a block is determined to have touched the ground converts it to a stationary block which is no longer
        effected by player actions
        """
        key_list = list(self.game.keys())
        my_dict = {}

        for (x, y) in key_list:
            if self.game.get((x, y)) == "Falling_Block" and (self.game.get(x, y + 1) == "Stationary_Block" or y + 1 == self.sizey):
                my_dict.clear()
                for key in key_list:
                    my_dict[key] = "Stationary_Block"
                break

            else:
                if self.game.get((x, y)) == "Stationary_Block":
                    my_dict[(x, y)] = "Stationary_Block"

                elif self.sizey <= y:
                    for key in key_list:
                        my_dict[key] = "Stationary_Block"

                elif self.game.get((x, y)) == "Falling_Block":
                    my_dict[(x, y)] = "Falling_Block"

        self.game.clear()
        self.game.update(my_dict)

Please do not do this. Paste the code inline directly, between triple
backticks:

```
your code here
```

Those of us on email do not see your pictiure. Those with vision
impairment (in a variety of forms) cannot see your picture. None of us
can cut/paste from your picture to try your code or to cite it to
suggest improvements.

Text! We like text!

Thanks,
Cameron Simpson cs@cskk.id.au

Thanks for letting me know, I tried to do this earlier but it messed up the formatting

Never mind, I just realised after literally spending hours looking at this that I just missed two brackets :L
Thanks to anyone who offered or wanted to offer help. I am just dumb

The triple backticks help with that. They say this is code, do not
mangle it. Have another go, we’re happy to try to figure out what isn’t
working.

Meanwhile I’ll go find that screenshot…

Cheers,
Cameron Simpson cs@cskk.id.au

No, we make these kinds of mistakes all the time. They can be hard to see.

Assertions and print statements can help narrow things down.

I see you’ve inserted your code in the original message. Thanks!

Cheers,
Cameron Simpson cs@cskk.id.au