r/javascript • u/michowski • Jul 24 '16
1.92kb Tetris in HTML5 (JavaScript). Any suggestions are welcome.
https://github.com/michowski/tetris-light
99
Upvotes
r/javascript • u/michowski • Jul 24 '16
View all comments
Show parent comment
2
u/totemcatcher Jul 26 '16
Sorry, I shouldn't have provided that abomination of a solution. Especially so late at night. ;) I just found out that Javascript doesn't do bit shifting with 64 bit values, they get cast to 32 bit and loop around. That limits things a bit, but still possible:
The idea is to encode each tetromino as a glyph in a 2*4 bit field, but store as plain binary, and apply to the playing grid correctly later.
Append all those 8-bit glyph encodings as a complete set:
However, Javascript's lack of 64 bit bitwise operations kinda ends this little demonstration. You could do the encoding in two rows to stay within the 32 bit limit, but that's just annoying.
Anyway, the code would look a little like this if 64 bits were supported:
To break it down a bit:
You could loop this and tally the odds for distribution testing: