# [Tutor] Improving My Simple Game Code for Speed, Memory and Learning

WolfRage wolfrage8765 at gmail.com
Mon Jan 12 01:57:01 CET 2015

I had an issue in my logic and again my named variables provided for

I got much closer by editing my code like this:

def drop_floating_nodes0(self):
i = self.rows
# first_zero_row serves as memory for how far to drop non-zero
values
first_zero_row = None
for col_list in self.transposed_grid:
while True:
# Low is on Top, High is on Bottom
low, high = col_list[i - 2: i]  # Goes Up the Rows
if high.value == 0:
if low.value != 0:
if first_zero_row is None:
high.value = low.value
low.value = 0
first_zero_row = low
else:
first_zero_row.value = low.value
low.value = 0
high.value = 0
first_zero_row = low
else:
if first_zero_row is None:
first_zero_row = high
i -= 1
if i == 1:
i = self.rows
first_zero_row = None
break

But it still fails as you can see here from the output:

| 20 | 19 | 11 | 20 |
| 11 |  5 |  5 | 11 |
| 19 |  5 | 11 | 11 |
| 19 | 20 | 20 |  5 |
| 11 | 19 | 19 | 11 |
| 20 |  6 |  6 | 11 |
| 19 | 11 |  5 | 20 |
| 11 | 20 | 11 | 20 |
After Eliminations
| 20 |  0 | 11 |  0 |
|  0 |  0 |  0 |  0 |
|  0 |  0 | 11 |  0 |
|  0 |  0 |  0 |  0 |
|  0 |  0 |  0 |  0 |
| 20 |  6 |  6 |  0 |
| 19 | 11 |  5 |  0 |
| 11 | 20 | 11 | 20 |
After Drops
|  0 |  0 |  0 |  0 |
|  0 |  0 |  0 |  0 |
|  0 |  0 | 11 |  0 |
|  0 |  0 |  0 |  0 |
| 20 |  0 | 11 |  0 |
| 20 |  6 |  6 |  0 |
| 19 | 11 |  5 |  0 |
| 11 | 20 | 11 | 20 |