4
Playing tetris is fun. Watching an AI play tetris is also fun.
Some tetris AIs will always ignore the possibility of maneuvering a piece under an overhang, which makes me sad.
It means that the programmer said to himself, "What are all the possible places the tile could be at the top of the board, and from each place, what happens when I hard drop the tile?"
The input of your program will be a game piece, a board, and a newline.
The output of your program will be two integers (with a space between them) and a newline.
Your program should generates all possible "moves", distinguishing those "moves" which could be produced by a naive AI (rotation and shifting left/right may only occur at the top), from those "moves" which can only be produced either the naive way or if rotation and horizontal shifting are allowed below the top.
The count of how many "moves" are in each of the two categories (smaller number first), are the two numbers output.
Each "move" is a game board where the tile has a +
square below it, or where the tile would go off the edge of the grid if it were moved one row downward.
The format of the game piece is a single byte which is one of s
z
l
j
o
i
). The board consists of 180 bytes, each being either space () or a plus (
+
), representing a grid 10 squares wide by 18 tall.
Each piece starts with the top row of its bounding box on the top grid row, and is centered, rounding to the left.
The piece letters represent the same tetrominoes used by what's called the Super Rotation System, and obviously the same rotations.
When maneuvering a piece, it may be shifted left or right, rotated clockwise or counterclockwise, or moved one row down, except if doing so will cause part of the piece to go off the edge or top or bottom of the grid, or overlap with any of the +
marks. There are no wall kicks.
Shortest source code wins.
I suggest (but don't require) that you use some sort of transposition table to avoid infinite loops of repeatedly shifting left/right, or rotating infinitely, etc.
3You need to include a description of how tetris pieces and boards and such work. Different tetris implementations handle rotating the I and Z/S pieces differently, and some do or don't allow rotating a piece into a space it couldn't otherwise move into. – Sparr – 2016-11-30T03:53:21.987
I think it's best to assume that a piece CANNOT be rotated, only moved left right, as it goes down. – Eyal Lev – 2016-11-30T11:50:44.790
3I like the idea, I just feel like this is the type of challenge that you need to post examples for. – Magic Octopus Urn – 2016-12-01T16:08:31.893