Tetris Piece Rotation Algorithm

前端 未结 15 884
傲寒
傲寒 2020-11-30 17:57

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 confu

15条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 18:12

    If you're doing this in python, cell-based instead of coordinate pairs it's very simple to rotate a nested list.

    rotate = lambda tetrad: zip(*tetrad[::-1])
    
    # S Tetrad
    tetrad = rotate([[0,0,0,0], [0,0,0,0], [0,1,1,0], [1,1,0,0]])
    

提交回复
热议问题