Looking at it now, the code has some warts. It was written on an airplane ride and I just noticed I mistakingly left out S and Z tetrominoes. Oops! It's also interesting to compare the difference in block representations with my C program; I definitely think my C representation (offsets rather than masks) is cleaner. With the Python mask representation, I use a nested list transpose to take care of rotations: list(reversed(zip(*shape))). While that's a neat APL-style idiom, Python isn't really giving me any leverage over C. For example, for clearing rows in Python I use list slice lvalues. Those are useful, but here C gets the job done just as conveniently with memmove and bzero.
Anyway, it could be a lot better, but it's still simpler than most of the tutorial-style game samples littering the net.
http://web.archive.org/web/20060208230531/http://www.cryptop...
Looking at it now, the code has some warts. It was written on an airplane ride and I just noticed I mistakingly left out S and Z tetrominoes. Oops! It's also interesting to compare the difference in block representations with my C program; I definitely think my C representation (offsets rather than masks) is cleaner. With the Python mask representation, I use a nested list transpose to take care of rotations: list(reversed(zip(*shape))). While that's a neat APL-style idiom, Python isn't really giving me any leverage over C. For example, for clearing rows in Python I use list slice lvalues. Those are useful, but here C gets the job done just as conveniently with memmove and bzero.
Anyway, it could be a lot better, but it's still simpler than most of the tutorial-style game samples littering the net.