Writing Tetris in Clojure
codethat.wordpress.com
codethat.wordpress.com
[1]: https://github.com/ztellman/penumbra/blob/master/test/exampl...
Can you demonstrate this? Or, can you show at least a plausible proof-of-concept?
I haven't tested it. I made sure it compiles and gave it a few looks over. There are likely going to be bugs but fixing them wouldn't lengthen the program.
cat tetris.cpp | sed '/^\s*$/d' | wc -l
162
That's not far off from my 150 estimate including rendering and input code.You're defining the term "in any way that is interesting" according to your prejudices and I am defining it according to mine. Let's leave it at that.
Zach's program is a lot nicer than what was originally posted. But please take a look at my program and tell me where additional abstractions would noticeably improve semantic and syntactic clarity. I can't find anything. The only thing that suggests itself is the recurring 'for (vector *v = t.v; v < t.v + 4; v++)' idiom. It's annoying to write bare-handed for loops, but I don't lose sleep over it.
Looking at the game logic in both examples, I'm convinced by psykotic. Both programs are fine, but the Clojure one doesn't seem to add any extra higher level cleanliness or abstraction, over the plain old C code.
Not to say that this holds in general, as code bases grow; or to take from the original tutorial in any way; just that I agree with that for a simple game like tetris, you don't see any benefit of the higher level abstractions, as implemented here.
Also, you have to give psykotic some credit for putting the time into writing a quick proof of concept to back up the opinion expressed!
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.
A C programmer? Yes and yes.
http://gametuto.com/tetris-tutorial-in-c-render-independent/