From c6804d4367ad73194a3fffd2ed0fc6315a55894d Mon Sep 17 00:00:00 2001 From: Rin Date: Sat, 21 Aug 2021 20:31:46 +0100 Subject: [PATCH] Add permissive rotation system --- tetris/rulesets/prs.lua | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tetris/rulesets/prs.lua diff --git a/tetris/rulesets/prs.lua b/tetris/rulesets/prs.lua new file mode 100644 index 0000000..6100ce3 --- /dev/null +++ b/tetris/rulesets/prs.lua @@ -0,0 +1,34 @@ +local SRS = require 'tetris.rulesets.standard' + +local PRS = SRS:extend() + +PRS.name = "Permissive Rotation System" +PRS.hash = "PRS" +PRS.world = true + +function PRS:attemptWallkicks(piece, newpiece, rot_dir, grid) + for y=0,5 do + for x=0,5 do + local offset = {x=x, y=y} + kicked_piece = newpiece:withOffset(offset) + if grid:canPlacePiece(kicked_piece) then + piece:setRelativeRotation(rot_dir) + piece:setOffset(offset) + self:onPieceRotate(piece, grid) + return + end + end + for x=0,5 do + local offset = {x=-x, y=y} + kicked_piece = newpiece:withOffset(offset) + if grid:canPlacePiece(kicked_piece) then + piece:setRelativeRotation(rot_dir) + piece:setOffset(offset) + self:onPieceRotate(piece, grid) + return + end + end + end +end + +return PRS \ No newline at end of file