俄罗斯方块片旋转算法算法、俄罗斯方块

2023-09-10 23:09:59 作者:当掉、呐宿命

什么是最好的算法(和解释)进行再presenting和旋转的俄罗斯方块游戏的作品?我总是发现一块旋转和重新presentation方案扑朔迷离。

What are the best algorithms (and explanations) for representing and rotating the pieces of a tetris game? I always find the piece rotation and representation schemes confusing.

大多数的俄罗斯方块游戏似乎使用一个天真的重拍块阵列在每次旋转:

Most tetris games seem to use a naive "remake the array of blocks" at each rotation:

http://www.$c$cplex.com/Project/ProjectDirectory.aspx?ProjectSearchText=tetris

然而,一些使用pre内置的连接codeD编号和位转移到重新present每件:

However, some use pre-built encoded numbers and bit shifting to represent each piece:

HTTP://www.$c$cplex.com/wintris

有没有办法做到这一点使用数学(不能肯定会工作在基于细胞的板)?

Is there a method to do this using mathematics (not sure that would work on a cell based board)?

推荐答案

有一个有限的形状,数量,所以我会用一个固定的表,也没有计算。这可以节省时间。

There is a limited amount of shapes, so I would use a fixed table and no calculation. That saves time.

但也有旋转算法。

选择了一个中心点和旋转丕/ 2。

Chose a centerpoint and rotate pi/2.

如果一块的块在(1,2)启动时,它顺时针移动到(2,-1)和(-1,-2)和(-1,2)。 应用此对于每个块和片被转动。

If a block of a piece starts at (1,2) it moves clockwise to (2,-1) and (-1,-2) and (-1, 2). Apply this for each block and the piece is rotated.

每个x是previous y和每个Y - 在previous的X.这样做具有下述矩阵:

Each x is the previous y and each y - the previous x. Which gives the following matrix:

[  0   1 ]
[ -1   0 ]

有关逆时针旋转,使用:

For counterclockwise rotation, use:

[  0  -1 ]
[  1   0 ]
 
精彩推荐
图片推荐