From d837b14c53ac1a829c916ec1cea2e1a0cf73df48 Mon Sep 17 00:00:00 2001 From: Ishaan Bhardwaj Date: Sat, 27 Nov 2021 16:08:54 -0500 Subject: [PATCH] Fixed IRS triggering transform in TransRS --- tetris/rulesets/trans.lua | 40 ++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/tetris/rulesets/trans.lua b/tetris/rulesets/trans.lua index 33e86e9..fe45433 100644 --- a/tetris/rulesets/trans.lua +++ b/tetris/rulesets/trans.lua @@ -21,28 +21,34 @@ function Trans:attemptRotate(new_inputs, piece, grid, initial) end local new_piece = piece:withRelativeRotation(rot_dir) + + if initial then + if (grid:canPlacePiece(new_piece)) then + self:onPieceRotate(piece, grid) + piece:setRelativeRotation(rot_dir) + end + else + self:attemptWallkicks(piece, new_piece, rot_dir, grid) + end +end + +function Trans:attemptWallkicks(piece, new_piece, rot_dir, grid) local pieces = {"I", "J", "L", "O", "S", "T", "Z"} repeat new_piece.shape = pieces[math.random(7)] until piece.shape ~= new_piece.shape - if (grid:canPlacePiece(new_piece)) then - self:onPieceRotate(piece, grid) - piece:setRelativeRotation(rot_dir) - piece.shape = new_piece.shape - else - if not(initial and self.enable_IRS_wallkicks == false) then - if (grid:canPlacePiece(new_piece:withOffset({x=1, y=0}))) then - self:onPieceRotate(piece, grid) - piece:setRelativeRotation(rot_dir):setOffset({x=1, y=0}) - piece.shape = new_piece.shape - elseif (grid:canPlacePiece(new_piece:withOffset({x=-1, y=0}))) then - self:onPieceRotate(piece, grid) - piece:setRelativeRotation(rot_dir):setOffset({x=-1, y=0}) - piece.shape = new_piece.shape - end - end - end + local offsets = {{x=0, y=0}, {x=1, y=0}, {x=-1, y=0}} + for _, o in pairs(offsets) do + local kicked_piece = new_piece:withOffset(o) + if (grid:canPlacePiece(kicked_piece)) then + self:onPieceRotate(piece, grid) + piece:setRelativeRotation(rot_dir) + piece:setOffset(o) + piece.shape = new_piece.shape + return + end + end end return Trans \ No newline at end of file