俄罗斯方块片旋转算法 [英] Tetris Piece Rotation Algorithm

查看:484
本文介绍了俄罗斯方块片旋转算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最好的算法(和解释)进行再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:

<一个href="http://www.$c$cplex.com/Project/ProjectDirectory.aspx?ProjectSearchText=tetris">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 ]

这篇关于俄罗斯方块片旋转算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆