37
5
Description
We consider a slightly simplified version of Tetris where each move consists of:
- rotating the piece clockwise, 0 to 3 times
- positioning the piece at a given column
- fast drop
The goal is to determine the number of completed lines, given a list of such Tetris moves.
Completed rows are removed as pieces are dropped, following standard Tetris rules.
Playfield
The playfield is 10-column wide. There's no Game Over and it is assumed that there's always enough space and time to perform the above actions, no matter the configuration of the playfield. The height of the playfield doesn't really matter here, but you can use the standard 22 rows as an upper limit.
Shapes of Tetrominoes
Input / Output
Input
A comma separated list of Tetris moves encoded with 3 characters. The first two character describe the Tetromino shape to use and the last one describes the position where it's dropped.
- Tetromino:
I
,O
,T
,L
,J
,Z
orS
, in the same order as above. - Number of clockwise rotations:
0
to3
- Column:
0
to9
. This is the column in which the top-left corner of the piece (marked with anx
on the above picture) is located after the rotation 1
It is assumed that all moves in the provided list are valid. There's no need to check for invalid entries such as I07
(horizontal I
shape put too far on the right).
1 You are free to either implement a real rotation algorithm or to hardcode all the different shapes, as long as the x
is located in the column given by the third character of the move.
Output
Number of completed lines.
Example
O00,T24
will generate the first position and O00,T24,S02,T01,L00,Z03,O07,L06,I05
will generate the second position.
Therefore, the following sequence will generate a Tetris and should return 4
:
O00,T24,S02,T01,L00,Z03,O07,L06,I05,I19
Test cases
1) "O00,T24,S02,T01,L00,Z03,O07,L06,I05,I19" -> 4
2) "S00,J03,L27,Z16,Z18,I10,T22,I01,I05,O01,L27,O05,S13" -> 5
3) "I01,T30,J18,L15,J37,I01,S15,L07,O03,O03,L00,Z00,T38,T01,S06,L18,L14" -> 4
4) "S14,T00,I13,I06,I05,I19,L20,J26,O07,Z14,Z10,Z12,O01,L27,L04,I03,S07,I01,T25,J23,J27,O01,
I10,I10" -> 8
5) "O00,T24,L32,T16,L04,Z11,O06,L03,I18,J30,L23,Z07,I19,T05,T18,L30,I01,I01,I05,T02" -> 8
Test page
You can use this JSFiddle to test a move list.
1What axis are the pieces rotated about? – None – 2016-08-18T18:14:41.823
(Voting to close as unclear until the rotation gets clarified.) This is a nice challenge, but it could've used some time in the Sandbox.
– Lynn – 2016-08-18T18:18:00.090@tuskiomi - It doesn't matter because the top left corner is the reference for the position of the piece. But I will try to update my question to illustrate this. – Arnauld – 2016-08-18T18:24:24.213
If you complete a line on top of an uncompleted line, do you delete that line immediately so that you can drop pieces into the uncompleted line? – Neil – 2016-08-18T18:32:16.990
@Neil - Yes. All completed lines are immediately removed. – Arnauld – 2016-08-18T18:34:40.700
1
@Arnauld I suggest you take a look at the super rotation system, and edit the image a teency bit. http://tetris.wikia.com/wiki/SRS
– None – 2016-08-18T18:57:52.873@tuskiomi - I'm a bit concerned about that. My fear is that going into rotation details will make the question appear more complicated than it actually is. The only rule is that the 3rd character in the move represents the column where the
x
goes. The implementation is left at the reader initiative. Please let me know if that makes sense. – Arnauld – 2016-08-18T19:24:57.9401So, we can treat these as 25 (15 if you don't count duplicates) different shapes, then? – None – 2016-08-18T19:42:28.190
@tuskiomi - Yes, exactly. The first two characters of the move essentially describe the shape to use, and the 3rd one the position where it's dropped. – Arnauld – 2016-08-18T19:43:57.550
what should we do in the case of an impossible piece?, eg: overlapping or off the edge? – None – 2016-08-18T19:51:18.800
Sounds like you're implementing a Keyblox macro evaluator. – Joe Z. – 2016-08-18T20:19:58.317
Can you add some more test cases? 4 seems a little light. Also it would be good if you could clarify that lines must be removed in the question — until I saw your comment I'd assumed that was another element you'd removed to simplify it. – Dave – 2016-08-18T20:32:22.147
@Dave - I've added a JSFiddle to test the move lists. Hopefully that should also help clarify the puzzle. – Arnauld – 2016-08-18T21:38:30.563
1Can solutions take input as an array rather than a comma-separated string? – Jordan – 2016-08-24T13:46:19.433
@Jordan - Yes. An array of strings such as
[ "O00", "T24", "S02", ... ]
would be fine. – Arnauld – 2016-08-24T20:10:09.7271This is the best PCG question I've seen for a long time. What a great idea! Best in the subjective sense of interesting and practical and not too big yet not too small. – GreenAsJade – 2017-01-20T23:47:06.927