tetris rotation

旧街凉风 提交于 2019-12-04 23:14:34

The Tetris Wiki specifies one way these so-called wall kicks are done:

A wall kick happens when a player rotates a piece when no space exists in the squares where that tetromino would normally occupy after the rotation. To compensate, the game sets a certain number of alternative spaces for the tetromino to look. [...] The simplest wall kick algorithm [...] is to try moving the tetromino one space to the right, and then one space to the left, and fail if neither can be done.

There are other ways, such as the one specified by the Super Rotation System mandated by the Tetris Guideline. That system uses a set of tables to determine the possible wall kicks.

If I understand your question correctly, there is no right answer. Whether you can "move through" other pieces depends on the guidelines for your particular assignment; it's possible to write code that allows it and code that doesn't.

Considering that field the tetris pieces fall are a matrix

1) If you want to give a little time for the user to rotate it and using your algorithm

  • Set a timer that starts when your lowest block is on a line adjacent to a line which the same column already has a piece.
  • If the user try to move that piece before the timer ends, check if there is a block on a line and column on which could be the place of one of the blocks of the movable piece. If it is already filled you can't move it

2) If you want to give a little time for the user to rotate it and using other algorithm

  • you can consider your block as a 3x3 cube and rotate it though the 2x2 block even if that doesn't exists on the piece (for example on a piece with the L format). So you just need to do what I said on the 2nd button of (1), and it should be fine! Thats an easier algorithm IMHO.

First of, you might want to clarify the terms in your question. In the first paragraph it seems that a "piece" is what others might call a "tile"; i.e., each tetromino is composed of four "pieces" or "tiles". But then at the end of the paragraph you call it a "block". And then, in the second paragraph it seems that "piece" is synonymous with "tetromino": "the piece has landed", "move his piece". So in your question, what do you mean? Perhaps "Which tile should the tetromino rotate around?"

If that is indeed your question, the answer is it's implementation-defined. If you try different versions of the game, you may see that in some, the "I" piece will wobble left-right or up-down as you put it through two rotations (the rotation tile is fixed on the tetromino), and in others it will not (the rotation toggles between the two center tiles such that a CW rotation will have the same effect as a CCW rotation). The "S" and "Z" pieces will similarly either wobble or not. If they don't wobble, though, you might find that a piece will be able to rotate when it's against the left wall but not if it's against the right, even though the situations should be symmetrical. And the square piece, if you leave it with a fixed rotation tile, will rotate around a corner when in all likelihood you want it to (appear to) not rotate at all. I've never seen an implementation that doesn't at least take care of that!

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