Search This Blog

Wednesday, October 6, 2010

Code Golf: Playing Tetris

Programmer Question

The basics:



Consider the following tetrominoes and empty playing field:




0123456789
I O Z T L S J [ ]
[ ]
# ## ## ### # ## # [ ]
# ## ## # # ## # [ ]
# ## ## [ ]
# [ ]
[ ]
[==========]


The dimensions of the playing field are fixed. The numbers at the top are just here
to indicate the column number (also see input).



Input:



1. You are given a specific playing field (based on the above) which can already be filled partly
with tetrominoes (this can be in a seperate file or provided via stdin).



Sample input:




[ ]
[ ]
[ ]
[ ]
[ # # #]
[ ## ######]
[==========]


2. You are given a string which describes (seperated by spaces) which tetromino to insert (and
drop down) at which column. Tetrominoes don't need to be rotated. Input can be read from stdin.



Sample input:



T2 Z6 I0 T7


You can assume input is 'well-formed' (or produce undefined behaviour when it's not).



Output



Render the resulting field ('full' lines must disappear) and print the score count
(every dropped line accounts for 10 points).



Sample output based on the sample input above:




[ ]
[ ]
[ ]
[# ###]
[# ### ]
[##### ####]
[==========]
10


Winner:



Shortest solution (by code character count). Usage examples are nice. Have fun golfing!



Edit: added a bounty of +500 reputation to draw some more attention to the nice efforts the answerers already made (and possibly some new solutions to this question)...



Find the answer here

No comments:

Post a Comment

Related Posts with Thumbnails