How can I generate a list of all Tetrominos?

余生颓废 提交于 2019-12-06 03:59:58

There are many ways to do this. One option that I've found works well is to think about it recursively and more generally. In particular:

  1. A single rectangle is a 1-omino.
  2. For any n-omino, you can create an (n+1)-omino by putting a block adjacent to any of the blocks from an n-omino.

This gives you a recursive way of listing all possible n-ominos. You need to be careful, though, since this will generate multiple rotations and translations of the same n-ominos. You can fix this by picking some reference coordinate system and then translating the n-omino so that it is always flush with the axes of that system. Once you've got that working, you can generate all rotations by just rotating the resulting n-omino around the axes, then translating it back to the canonical position.

The biggest grid you need for an N-omino is NxN. Generate all then exclude rotations and translations.

You can think of it as a path-following algorithm in N-1 steps. If you start from the top-left cell of the grid and only move right or down from there, you will avoid most translations and rotations. If I'm not mistaken, the only ones that will be left are the isomorphic N-ominones. E.G. the tetromino made by the path Right-Down-Left is the same as Down-Right-Up.

Tetrominos are shapes. Computers do not have direct representation of shapes, they have representations of numbers as binary signals. You, the programmer, determine how you want to represent a shape as a number. They can be stored as bitmaps, strings, an enum...

You'll have to write a much clearer question if you want specific help.

I'm also curious why you want to generate a list of 7 known, unchanging shapes. If you were writing a Tetris game, you would hardcode those 7 shapes somewhere, as variables, constants or images, not generate them.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!