Generating N-D Tetris Pieces - Dave's Blog

Search
My timeline on Mastodon

Generating N-D Tetris Pieces

2008 Jun 1, 7:27

When I woke up this morning for some reason I was thinking about Polytope Tetris, my N-D Tetris game, and specifically generating Tetris pieces in various number of dimensions. When I first wrote PTT I thought that as the number of dimensions increased you could end up with an infinite number of non-equivalent crazy Tetris pieces. However this morning I realized that because you only get four blocks per piece there are only a possible three joints in a single Tetris piece which means that you only need three dimensions to represent all possible distinct N-D Tetris pieces.

Below is the table of the various possible pieces per number of dimensions and sorted by the number of joints in the piece. Notice that the 'J' and 'L' become equivalent in 3D because you can rotate the 'J' through the third dimension to make it an 'L'. The same happens for 'S' and 'Z' in 3D, and 'S+' and 'Z+' in 4D.

Joints Name 1D 2D 3D +
1 I I I I I
2 J J J J
L L
3 O O O O
T T T T
S S S S
Z Z
T+ T+ T+
S+ S+ S+
Z+ Z+
Total 1 7 8 7

As a consequence of not realizing there's a finite and small number of N-D Tetris pieces, I wrote code that would randomly generate pieces for a specified number of dimensions by wandering through Tetris space. This consists of first marking the current spot, then randomly picking a direction (a dimension and either forward or backward), going in that direction until hitting a previously unvisited spot and repeating until four spots are marked, forming a Tetris piece. However this morning I realized that continuing in the same direction until reaching am unvisited spot means I can't generate the 'T+' piece. I think the better way to go is keep the list of all possible pieces, pick one randomly, and rotate it randomly through the available dimensions. Doing this will also allow me to give distinct pieces their own specific color (like the classic Tetris games do) rather than picking the color randomly like I do now.

PermalinkCommentspolytope tetris tetris
Older Entries Creative Commons License Some rights reserved.