This project is an implementation of a bot which can play automatically by performing tetrises1. The bot looks recursively n moves into the future, evaluates the board, and chooses the move which leads to the board state with the best score. This is achieved by bruteforcing combinations of pieces in the queue not resulting in holes. This includes swapping pieces in and out of the hold queue.
You can view the project here.
It is to be mentioned that this bot fails on the first move approximately 6.7% of the time. This is due to the fact that any combinations of the s and z piece in the first 2 positions of the queue, or the s, z, and o piece in the first 3 positions, will not leave any moves resulting in no holes2. There is a very simple way of handling this exception which I employed in a previous version of the Tetris bot. You can place the troubling piece left-most and rotate it in such a manor that the resulting holes always land in the empty column. This can be used to not only the resolve the starting exception, but also prolong the point of no valid moves. This is currently not implemented.
As this project is built using vanilla javascript, all you need is to open index.html in your browser. Press SPACE for placing pieces one at a time, and R for repeated placements. Note that the bot only places a piece if there is an avalaible move that results in no holes and respects the height limit. Refresh the page in case it gets stuck.
