diff --git a/tetris/rulesets/arika.lua b/tetris/rulesets/arika.lua index 4b7280f..5441eca 100644 --- a/tetris/rulesets/arika.lua +++ b/tetris/rulesets/arika.lua @@ -97,11 +97,11 @@ function ARS:attemptWallkicks(piece, new_piece, rot_dir, grid) -- kick right, kick left if (grid:canPlacePiece(new_piece:withOffset({x=1, y=0}))) then + self:onPieceRotate(piece, grid) piece:setRelativeRotation(rot_dir):setOffset({x=1, y=0}) - self:onPieceRotate(piece, grid) elseif (grid:canPlacePiece(new_piece:withOffset({x=-1, y=0}))) then - piece:setRelativeRotation(rot_dir):setOffset({x=-1, y=0}) self:onPieceRotate(piece, grid) + piece:setRelativeRotation(rot_dir):setOffset({x=-1, y=0}) end end diff --git a/tetris/rulesets/arika_ace.lua b/tetris/rulesets/arika_ace.lua index f34781f..ee5e602 100755 --- a/tetris/rulesets/arika_ace.lua +++ b/tetris/rulesets/arika_ace.lua @@ -1,5 +1,5 @@ local Piece = require 'tetris.components.piece' -local Ruleset = require 'tetris.rulesets.ruleset' +local Ruleset = require 'tetris.rulesets.arika_ti' local ARS = Ruleset:extend() @@ -39,136 +39,11 @@ ARS.big_spawn_positions = { Z = { x=2, y=1 }, } -ARS.block_offsets = { - I={ - { {x=0, y=0}, {x=-1, y=0}, {x=-2, y=0}, {x=1, y=0} }, - { {x=0, y=0}, {x=0, y=-1}, {x=0, y=1}, {x=0, y=2} }, - { {x=0, y=0}, {x=-1, y=0}, {x=-2, y=0}, {x=1, y=0} }, - { {x=0, y=0}, {x=0, y=-1}, {x=0, y=1}, {x=0, y=2} }, - }, - J={ - { {x=0, y=0}, {x=-1, y=0}, {x=1, y=0}, {x=-1, y=-1} }, - { {x=0, y=-1}, {x=1, y=-2}, {x=0, y=-2}, {x=0, y=0} }, - { {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=-1}, {x=1, y=0} }, - { {x=0, y=-1}, {x=0, y=-2}, {x=0, y=0}, {x=-1, y=0} }, - }, - L={ - { {x=0, y=0}, {x=-1, y=0}, {x=1, y=0}, {x=1, y=-1} }, - { {x=0, y=-2}, {x=0, y=-1}, {x=1, y=0}, {x=0, y=0} }, - { {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=-1}, {x=-1, y=0} }, - { {x=0, y=-1}, {x=-1, y=-2}, {x=0, y=-2}, {x=0, y=0} }, - }, - O={ - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - }, - S={ - { {x=1, y=-1}, {x=0, y=-1}, {x=0, y=0}, {x=-1, y=0} }, - { {x=-1, y=-2}, {x=-1, y=-1}, {x=0, y=-1}, {x=0, y=0} }, - { {x=1, y=-1}, {x=0, y=-1}, {x=0, y=0}, {x=-1, y=0} }, - { {x=-1, y=-2}, {x=-1, y=-1}, {x=0, y=-1}, {x=0, y=0} }, - }, - T={ - { {x=0, y=0}, {x=-1, y=0}, {x=1, y=0}, {x=0, y=-1} }, - { {x=0, y=-1}, {x=0, y=0}, {x=1, y=-1}, {x=0, y=-2} }, - { {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=-1}, {x=0, y=0} }, - { {x=0, y=-1}, {x=0, y=0}, {x=-1, y=-1}, {x=0, y=-2} }, - }, - Z={ - { {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=0}, {x=0, y=0} }, - { {x=0, y=-1}, {x=0, y=0}, {x=1, y=-2}, {x=1, y=-1} }, - { {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=0}, {x=0, y=0} }, - { {x=0, y=-1}, {x=0, y=0}, {x=1, y=-2}, {x=1, y=-1} }, - } -} - - --- Component functions. - -function ARS:attemptWallkicks(piece, new_piece, rot_dir, grid) - - -- O doesn't kick - if (piece.shape == "O") then return end - - -- center column rule - if ( - piece.shape == "J" or piece.shape == "T" or piece.shape == "L" - ) and ( - piece.rotation == 0 or piece.rotation == 2 - ) then - local offsets = new_piece:getBlockOffsets() - table.sort(offsets, function(A, B) return A.y < B.y or A.y == B.y and A.x < B.y end) - for index, offset in pairs(offsets) do - if grid:isOccupied(piece.position.x + offset.x, piece.position.y + offset.y) then - if offset.x == 0 then - return - else - break - end - end - end - end - - if piece.shape == "I" then - -- special kick rules for I - if new_piece.rotation == 0 or new_piece.rotation == 2 and - (piece:isMoveBlocked(grid, {x=-1, y=0}) or piece:isMoveBlocked(grid, {x=1, y=0})) then - -- kick right, right2, left - if grid:canPlacePiece(new_piece:withOffset({x=1, y=0})) then - piece:setRelativeRotation(rot_dir):setOffset({x=1, y=0}) - self:onPieceRotate(piece, grid) - elseif grid:canPlacePiece(new_piece:withOffset({x=2, y=0})) then - piece:setRelativeRotation(rot_dir):setOffset({x=2, y=0}) - self:onPieceRotate(piece, grid) - elseif grid:canPlacePiece(new_piece:withOffset({x=-1, y=0})) then - piece:setRelativeRotation(rot_dir):setOffset({x=-1, y=0}) - self:onPieceRotate(piece, grid) - end - elseif piece:isDropBlocked(grid) and (new_piece.rotation == 1 or new_piece.rotation == 3) and piece.floorkick == 0 then - -- kick up, up2 - if grid:canPlacePiece(new_piece:withOffset({x=0, y=-1})) then - piece:setRelativeRotation(rot_dir):setOffset({x=0, y=-1}) - self:onPieceRotate(piece, grid) - piece.floorkick = 1 - elseif grid:canPlacePiece(new_piece:withOffset({x=0, y=-2})) then - piece:setRelativeRotation(rot_dir):setOffset({x=0, y=-2}) - self:onPieceRotate(piece, grid) - piece.floorkick = 1 - end - end - else - -- kick right, kick left - if grid:canPlacePiece(new_piece:withOffset({x=1, y=0})) then - piece:setRelativeRotation(rot_dir):setOffset({x=1, y=0}) - elseif grid:canPlacePiece(new_piece:withOffset({x=-1, y=0})) then - piece:setRelativeRotation(rot_dir):setOffset({x=-1, y=0}) - elseif piece.shape == "T" - and new_piece.rotation == 0 - and piece.floorkick == 0 - and grid:canPlacePiece(new_piece:withOffset({x=0, y=-1})) - then - -- T floorkick - piece.floorkick = piece.floorkick + 1 - piece:setRelativeRotation(rot_dir):setOffset({x=0, y=-1}) - end - end - -end - function ARS:onPieceCreate(piece, grid) piece.floorkick = 0 piece.manipulations = 0 end -function ARS:onPieceDrop(piece, grid) - piece.lock_delay = 0 -- step reset - if piece.floorkick >= 2 and piece:isDropBlocked(grid) then - piece.locked = true - end -end - function ARS:onPieceMove(piece, grid) piece.lock_delay = 0 -- move reset if piece:isDropBlocked(grid) then @@ -192,14 +67,4 @@ function ARS:onPieceRotate(piece, grid) end end -function ARS:get180RotationValue() - if config.gamesettings.world_reverse == 3 then - return 1 - else - return 3 - end -end - -function ARS:getDefaultOrientation() return 3 end -- downward facing pieces by default - return ARS diff --git a/tetris/rulesets/arika_ace2.lua b/tetris/rulesets/arika_ace2.lua index 703245e..fb797ae 100644 --- a/tetris/rulesets/arika_ace2.lua +++ b/tetris/rulesets/arika_ace2.lua @@ -1,5 +1,5 @@ local Piece = require 'tetris.components.piece' -local Ruleset = require 'tetris.rulesets.ruleset' +local Ruleset = require 'tetris.rulesets.arika_ti' local ARS = Ruleset:extend() @@ -26,136 +26,11 @@ ARS.big_spawn_positions = { Z = { x=2, y=1 }, } -ARS.block_offsets = { - I={ - { {x=0, y=0}, {x=-1, y=0}, {x=-2, y=0}, {x=1, y=0} }, - { {x=0, y=0}, {x=0, y=-1}, {x=0, y=1}, {x=0, y=2} }, - { {x=0, y=0}, {x=-1, y=0}, {x=-2, y=0}, {x=1, y=0} }, - { {x=0, y=0}, {x=0, y=-1}, {x=0, y=1}, {x=0, y=2} }, - }, - J={ - { {x=0, y=0}, {x=-1, y=0}, {x=1, y=0}, {x=-1, y=-1} }, - { {x=0, y=-1}, {x=1, y=-2}, {x=0, y=-2}, {x=0, y=0} }, - { {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=-1}, {x=1, y=0} }, - { {x=0, y=-1}, {x=0, y=-2}, {x=0, y=0}, {x=-1, y=0} }, - }, - L={ - { {x=0, y=0}, {x=-1, y=0}, {x=1, y=0}, {x=1, y=-1} }, - { {x=0, y=-2}, {x=0, y=-1}, {x=1, y=0}, {x=0, y=0} }, - { {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=-1}, {x=-1, y=0} }, - { {x=0, y=-1}, {x=-1, y=-2}, {x=0, y=-2}, {x=0, y=0} }, - }, - O={ - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - }, - S={ - { {x=1, y=-1}, {x=0, y=-1}, {x=0, y=0}, {x=-1, y=0} }, - { {x=-1, y=-2}, {x=-1, y=-1}, {x=0, y=-1}, {x=0, y=0} }, - { {x=1, y=-1}, {x=0, y=-1}, {x=0, y=0}, {x=-1, y=0} }, - { {x=-1, y=-2}, {x=-1, y=-1}, {x=0, y=-1}, {x=0, y=0} }, - }, - T={ - { {x=0, y=0}, {x=-1, y=0}, {x=1, y=0}, {x=0, y=-1} }, - { {x=0, y=-1}, {x=0, y=0}, {x=1, y=-1}, {x=0, y=-2} }, - { {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=-1}, {x=0, y=0} }, - { {x=0, y=-1}, {x=0, y=0}, {x=-1, y=-1}, {x=0, y=-2} }, - }, - Z={ - { {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=0}, {x=0, y=0} }, - { {x=0, y=-1}, {x=0, y=0}, {x=1, y=-2}, {x=1, y=-1} }, - { {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=0}, {x=0, y=0} }, - { {x=0, y=-1}, {x=0, y=0}, {x=1, y=-2}, {x=1, y=-1} }, - } -} - - --- Component functions. - -function ARS:attemptWallkicks(piece, new_piece, rot_dir, grid) - - -- O doesn't kick - if (piece.shape == "O") then return end - - -- center column rule - if ( - piece.shape == "J" or piece.shape == "T" or piece.shape == "L" - ) and ( - piece.rotation == 0 or piece.rotation == 2 - ) then - local offsets = new_piece:getBlockOffsets() - table.sort(offsets, function(A, B) return A.y < B.y or A.y == B.y and A.x < B.y end) - for index, offset in pairs(offsets) do - if grid:isOccupied(piece.position.x + offset.x, piece.position.y + offset.y) then - if offset.x == 0 then - return - else - break - end - end - end - end - - if piece.shape == "I" then - -- special kick rules for I - if new_piece.rotation == 0 or new_piece.rotation == 2 and - (piece:isMoveBlocked(grid, {x=-1, y=0}) or piece:isMoveBlocked(grid, {x=1, y=0})) then - -- kick right, right2, left - if grid:canPlacePiece(new_piece:withOffset({x=1, y=0})) then - piece:setRelativeRotation(rot_dir):setOffset({x=1, y=0}) - self:onPieceRotate(piece, grid) - elseif grid:canPlacePiece(new_piece:withOffset({x=2, y=0})) then - piece:setRelativeRotation(rot_dir):setOffset({x=2, y=0}) - self:onPieceRotate(piece, grid) - elseif grid:canPlacePiece(new_piece:withOffset({x=-1, y=0})) then - piece:setRelativeRotation(rot_dir):setOffset({x=-1, y=0}) - self:onPieceRotate(piece, grid) - end - elseif piece:isDropBlocked(grid) and (new_piece.rotation == 1 or new_piece.rotation == 3) and piece.floorkick == 0 then - -- kick up, up2 - if grid:canPlacePiece(new_piece:withOffset({x=0, y=-1})) then - piece:setRelativeRotation(rot_dir):setOffset({x=0, y=-1}) - self:onPieceRotate(piece, grid) - piece.floorkick = 1 - elseif grid:canPlacePiece(new_piece:withOffset({x=0, y=-2})) then - piece:setRelativeRotation(rot_dir):setOffset({x=0, y=-2}) - self:onPieceRotate(piece, grid) - piece.floorkick = 1 - end - end - else - -- kick right, kick left - if grid:canPlacePiece(new_piece:withOffset({x=1, y=0})) then - piece:setRelativeRotation(rot_dir):setOffset({x=1, y=0}) - elseif grid:canPlacePiece(new_piece:withOffset({x=-1, y=0})) then - piece:setRelativeRotation(rot_dir):setOffset({x=-1, y=0}) - elseif piece.shape == "T" - and new_piece.rotation == 0 - and piece.floorkick == 0 - and grid:canPlacePiece(new_piece:withOffset({x=0, y=-1})) - then - -- T floorkick - piece.floorkick = piece.floorkick + 1 - piece:setRelativeRotation(rot_dir):setOffset({x=0, y=-1}) - end - end - -end - function ARS:onPieceCreate(piece, grid) piece.floorkick = 0 piece.manipulations = 0 end -function ARS:onPieceDrop(piece, grid) - piece.lock_delay = 0 -- step reset - if piece.floorkick >= 2 and piece:isDropBlocked(grid) then - piece.locked = true - end -end - function ARS:onPieceMove(piece, grid) piece.lock_delay = 0 -- move reset if piece:isDropBlocked(grid) then @@ -179,14 +54,4 @@ function ARS:onPieceRotate(piece, grid) end end -function ARS:get180RotationValue() - if config.gamesettings.world_reverse == 3 then - return 1 - else - return 3 - end -end - -function ARS:getDefaultOrientation() return 3 end -- downward facing pieces by default - return ARS diff --git a/tetris/rulesets/arika_srs.lua b/tetris/rulesets/arika_srs.lua index f72c715..323bc3c 100755 --- a/tetris/rulesets/arika_srs.lua +++ b/tetris/rulesets/arika_srs.lua @@ -1,22 +1,10 @@ local Piece = require 'tetris.components.piece' -local Ruleset = require 'tetris.rulesets.ruleset' +local Ruleset = require 'tetris.rulesets.ti_srs' local SRS = Ruleset:extend() SRS.name = "ACE-SRS" SRS.hash = "ACE Standard" -SRS.world = true -SRS.colourscheme = { - I = "C", - L = "O", - J = "B", - S = "G", - Z = "R", - O = "Y", - T = "M", -} -SRS.softdrop_lock = false -SRS.harddrop_lock = true SRS.spawn_positions = { I = { x=5, y=2 }, @@ -38,132 +26,6 @@ SRS.big_spawn_positions = { Z = { x=2, y=1 }, } -SRS.block_offsets = { - I={ - { {x=0, y=0}, {x=-1, y=0}, {x=-2, y=0}, {x=1, y=0} }, - { {x=0, y=0}, {x=0, y=-1}, {x=0, y=1}, {x=0, y=2} }, - { {x=0, y=1}, {x=-1, y=1}, {x=-2, y=1}, {x=1, y=1} }, - { {x=-1, y=0}, {x=-1, y=-1}, {x=-1, y=1}, {x=-1, y=2} }, - }, - J={ - { {x=0, y=0}, {x=-1, y=0}, {x=1, y=0}, {x=-1, y=-1} }, - { {x=0, y=0}, {x=0, y=-1}, {x=0, y=1} , {x=1, y=-1} }, - { {x=0, y=0}, {x=1, y=0}, {x=-1, y=0}, {x=1, y=1} }, - { {x=0, y=0}, {x=0, y=1}, {x=0, y=-1}, {x=-1, y=1} }, - }, - L={ - { {x=0, y=0}, {x=-1, y=0}, {x=1, y=0}, {x=1, y=-1} }, - { {x=0, y=0}, {x=0, y=-1}, {x=0, y=1}, {x=1, y=1} }, - { {x=0, y=0}, {x=1, y=0}, {x=-1, y=0}, {x=-1, y=1} }, - { {x=0, y=0}, {x=0, y=1}, {x=0, y=-1}, {x=-1, y=-1} }, - }, - O={ - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - }, - S={ - { {x=1, y=-1}, {x=0, y=-1}, {x=0, y=0}, {x=-1, y=0} }, - { {x=1, y=1}, {x=1, y=0}, {x=0, y=0}, {x=0, y=-1} }, - { {x=-1, y=1}, {x=0, y=1}, {x=0, y=0}, {x=1, y=0} }, - { {x=-1, y=-1}, {x=-1, y=0}, {x=0, y=0}, {x=0, y=1} }, - }, - T={ - { {x=0, y=0}, {x=-1, y=0}, {x=1, y=0}, {x=0, y=-1} }, - { {x=0, y=0}, {x=0, y=-1}, {x=0, y=1}, {x=1, y=0} }, - { {x=0, y=0}, {x=1, y=0}, {x=-1, y=0}, {x=0, y=1} }, - { {x=0, y=0}, {x=0, y=1}, {x=0, y=-1}, {x=-1, y=0} }, - }, - Z={ - { {x=-1, y=-1}, {x=0, y=-1}, {x=0, y=0}, {x=1, y=0} }, - { {x=1, y=-1}, {x=1, y=0}, {x=0, y=0}, {x=0, y=1} }, - { {x=1, y=1}, {x=0, y=1}, {x=0, y=0}, {x=-1, y=0} }, - { {x=-1, y=1}, {x=-1, y=0}, {x=0, y=0}, {x=0, y=-1} }, - } -} - -SRS.wallkicks_3x3 = { - [0]={ - [1]={{x=-1, y=0}, {x=-1, y=-1}, {x=0, y=2}, {x=-1, y=2}}, - [2]={{x=0, y=1}, {x=0, y=-1}}, - [3]={{x=1, y=0}, {x=1, y=-1}, {x=0, y=2}, {x=1, y=2}}, - }, - [1]={ - [0]={{x=1, y=0}, {x=1, y=1}, {x=0, y=-2}, {x=1, y=-2}}, - [2]={{x=1, y=0}, {x=1, y=1}, {x=0, y=-2}, {x=1, y=-2}}, - [3]={{x=0, y=1}, {x=0, y=-1}}, - }, - [2]={ - [0]={{x=0, y=1}, {x=0, y=-1}}, - [1]={{x=-1, y=0}, {x=-1, y=-1}, {x=0, y=2}, {x=-1, y=2}}, - [3]={{x=1, y=0}, {x=1, y=-1}, {x=0, y=2}, {x=1, y=2}}, - }, - [3]={ - [0]={{x=-1, y=0}, {x=-1, y=1}, {x=0, y=-2}, {x=-1, y=-2}}, - [1]={{x=0, y=1}, {x=0, y=-1}}, - [2]={{x=-1, y=0}, {x=-1, y=1}, {x=0, y=-2}, {x=-1, y=-2}}, - }, -}; - -SRS.wallkicks_line = { - [0]={ - [1]={{x=-2, y= 0}, {x= 1, y= 0}, {x= 1, y=-2}, {x=-2, y= 1}}, - [2]={}, - [3]={{x= 2, y= 0}, {x=-1, y= 0}, {x=-1, y=-2}, {x= 2, y= 1}}, - }, - [1]={ - [0]={{x= 2, y= 0}, {x=-1, y= 0}, {x= 2, y=-1}, {x=-1, y= 2}}, - [2]={{x=-1, y= 0}, {x= 2, y= 0}, {x=-1, y=-2}, {x= 2, y= 1}}, - [3]={}, - }, - [2]={ - [0]={}, - [1]={{x=-2, y= 0}, {x= 1, y= 0}, {x=-2, y=-1}, {x= 1, y= 1}}, - [3]={{x= 2, y= 0}, {x=-1, y= 0}, {x= 2, y=-1}, {x=-1, y= 1}}, - }, - [3]={ - [0]={{x=-2, y= 0}, {x= 1, y= 0}, {x=-2, y=-1}, {x= 1, y= 2}}, - [1]={}, - [2]={{x= 1, y= 0}, {x=-2, y= 0}, {x= 1, y=-2}, {x=-2, y= 1}}, - }, -}; - --- Component functions. - -function SRS:attemptWallkicks(piece, new_piece, rot_dir, grid) - - local kicks - if piece.shape == "O" then - return - elseif piece.shape == "I" then - kicks = SRS.wallkicks_line[piece.rotation][new_piece.rotation] - else - kicks = SRS.wallkicks_3x3[piece.rotation][new_piece.rotation] - end - - assert(piece.rotation ~= new_piece.rotation) - - for idx, offset in pairs(kicks) do - kicked_piece = new_piece:withOffset(offset) - if grid:canPlacePiece(kicked_piece) then - self:onPieceRotate(piece, grid) - piece:setRelativeRotation(rot_dir) - piece:setOffset(offset) - return - end - end - -end - -function SRS:onPieceCreate(piece, grid) - piece.manipulations = 0 -end - -function SRS:onPieceDrop(piece, grid) - piece.lock_delay = 0 -- step reset -end - function SRS:onPieceMove(piece, grid) piece.lock_delay = 0 -- move reset if piece:isDropBlocked(grid) then @@ -184,12 +46,4 @@ function SRS:onPieceRotate(piece, grid) end end -function SRS:get180RotationValue() - if config.gamesettings.world_reverse == 1 then - return 1 - else - return 3 - end -end - return SRS diff --git a/tetris/rulesets/arika_ti.lua b/tetris/rulesets/arika_ti.lua index 10cf620..5ef7779 100644 --- a/tetris/rulesets/arika_ti.lua +++ b/tetris/rulesets/arika_ti.lua @@ -1,77 +1,11 @@ local Piece = require 'tetris.components.piece' -local Ruleset = require 'tetris.rulesets.ruleset' +local Ruleset = require 'tetris.rulesets.arika' local ARS = Ruleset:extend() ARS.name = "Ti-ARS" ARS.hash = "ArikaTI" -ARS.spawn_positions = { - I = { x=5, y=4 }, - J = { x=4, y=5 }, - L = { x=4, y=5 }, - O = { x=5, y=5 }, - S = { x=4, y=5 }, - T = { x=4, y=5 }, - Z = { x=4, y=5 }, -} - -ARS.big_spawn_positions = { - I = { x=3, y=2 }, - J = { x=2, y=3 }, - L = { x=2, y=3 }, - O = { x=3, y=3 }, - S = { x=2, y=3 }, - T = { x=2, y=3 }, - Z = { x=2, y=3 }, -} - -ARS.block_offsets = { - I={ - { {x=0, y=0}, {x=-1, y=0}, {x=-2, y=0}, {x=1, y=0} }, - { {x=0, y=0}, {x=0, y=-1}, {x=0, y=1}, {x=0, y=2} }, - { {x=0, y=0}, {x=-1, y=0}, {x=-2, y=0}, {x=1, y=0} }, - { {x=0, y=0}, {x=0, y=-1}, {x=0, y=1}, {x=0, y=2} }, - }, - J={ - { {x=0, y=0}, {x=-1, y=0}, {x=1, y=0}, {x=-1, y=-1} }, - { {x=0, y=-1}, {x=1, y=-2}, {x=0, y=-2}, {x=0, y=0} }, - { {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=-1}, {x=1, y=0} }, - { {x=0, y=-1}, {x=0, y=-2}, {x=0, y=0}, {x=-1, y=0} }, - }, - L={ - { {x=0, y=0}, {x=-1, y=0}, {x=1, y=0}, {x=1, y=-1} }, - { {x=0, y=-2}, {x=0, y=-1}, {x=1, y=0}, {x=0, y=0} }, - { {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=-1}, {x=-1, y=0} }, - { {x=0, y=-1}, {x=-1, y=-2}, {x=0, y=-2}, {x=0, y=0} }, - }, - O={ - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - }, - S={ - { {x=1, y=-1}, {x=0, y=-1}, {x=0, y=0}, {x=-1, y=0} }, - { {x=-1, y=-2}, {x=-1, y=-1}, {x=0, y=-1}, {x=0, y=0} }, - { {x=1, y=-1}, {x=0, y=-1}, {x=0, y=0}, {x=-1, y=0} }, - { {x=-1, y=-2}, {x=-1, y=-1}, {x=0, y=-1}, {x=0, y=0} }, - }, - T={ - { {x=0, y=0}, {x=-1, y=0}, {x=1, y=0}, {x=0, y=-1} }, - { {x=0, y=-1}, {x=0, y=0}, {x=1, y=-1}, {x=0, y=-2} }, - { {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=-1}, {x=0, y=0} }, - { {x=0, y=-1}, {x=0, y=0}, {x=-1, y=-1}, {x=0, y=-2} }, - }, - Z={ - { {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=0}, {x=0, y=0} }, - { {x=0, y=-1}, {x=0, y=0}, {x=1, y=-2}, {x=1, y=-1} }, - { {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=0}, {x=0, y=0} }, - { {x=0, y=-1}, {x=0, y=0}, {x=1, y=-2}, {x=1, y=-1} }, - } -} - - -- Component functions. function ARS:attemptWallkicks(piece, new_piece, rot_dir, grid) @@ -104,32 +38,34 @@ function ARS:attemptWallkicks(piece, new_piece, rot_dir, grid) (piece:isMoveBlocked(grid, {x=-1, y=0}) or piece:isMoveBlocked(grid, {x=1, y=0})) then -- kick right, right2, left if grid:canPlacePiece(new_piece:withOffset({x=1, y=0})) then + self:onPieceRotate(piece, grid) piece:setRelativeRotation(rot_dir):setOffset({x=1, y=0}) - self:onPieceRotate(piece, grid) elseif grid:canPlacePiece(new_piece:withOffset({x=2, y=0})) then + self:onPieceRotate(piece, grid) piece:setRelativeRotation(rot_dir):setOffset({x=2, y=0}) - self:onPieceRotate(piece, grid) elseif grid:canPlacePiece(new_piece:withOffset({x=-1, y=0})) then - piece:setRelativeRotation(rot_dir):setOffset({x=-1, y=0}) self:onPieceRotate(piece, grid) + piece:setRelativeRotation(rot_dir):setOffset({x=-1, y=0}) end elseif piece:isDropBlocked(grid) and (new_piece.rotation == 1 or new_piece.rotation == 3) and piece.floorkick == 0 then -- kick up, up2 if grid:canPlacePiece(new_piece:withOffset({x=0, y=-1})) then - piece:setRelativeRotation(rot_dir):setOffset({x=0, y=-1}) self:onPieceRotate(piece, grid) + piece:setRelativeRotation(rot_dir):setOffset({x=0, y=-1}) piece.floorkick = 1 elseif grid:canPlacePiece(new_piece:withOffset({x=0, y=-2})) then - piece:setRelativeRotation(rot_dir):setOffset({x=0, y=-2}) self:onPieceRotate(piece, grid) + piece:setRelativeRotation(rot_dir):setOffset({x=0, y=-2}) piece.floorkick = 1 end end else -- kick right, kick left if grid:canPlacePiece(new_piece:withOffset({x=1, y=0})) then + self:onPieceRotate(piece, grid) piece:setRelativeRotation(rot_dir):setOffset({x=1, y=0}) elseif grid:canPlacePiece(new_piece:withOffset({x=-1, y=0})) then + self:onPieceRotate(piece, grid) piece:setRelativeRotation(rot_dir):setOffset({x=-1, y=0}) elseif piece.shape == "T" and new_piece.rotation == 0 @@ -138,6 +74,7 @@ function ARS:attemptWallkicks(piece, new_piece, rot_dir, grid) then -- T floorkick piece.floorkick = piece.floorkick + 1 + self:onPieceRotate(piece, grid) piece:setRelativeRotation(rot_dir):setOffset({x=0, y=-1}) end end @@ -161,14 +98,4 @@ function ARS:onPieceRotate(piece, grid) end end -function ARS:get180RotationValue() - if config.gamesettings.world_reverse == 3 then - return 1 - else - return 3 - end -end - -function ARS:getDefaultOrientation() return 3 end -- downward facing pieces by default - return ARS diff --git a/tetris/rulesets/cambridge.lua b/tetris/rulesets/cambridge.lua index 4aaf96a..a82a5c7 100644 --- a/tetris/rulesets/cambridge.lua +++ b/tetris/rulesets/cambridge.lua @@ -384,9 +384,9 @@ function CRS:attemptWallkicks(piece, new_piece, rot_dir, grid) for idx, offset in pairs(kicks) do kicked_piece = new_piece:withOffset(offset) if grid:canPlacePiece(kicked_piece) then + self:onPieceRotate(piece, grid) piece:setRelativeRotation(rot_dir) piece:setOffset(offset) - self:onPieceRotate(piece, grid) return end end diff --git a/tetris/rulesets/ruleset.lua b/tetris/rulesets/ruleset.lua index f1e8f56..ccd1220 100644 --- a/tetris/rulesets/ruleset.lua +++ b/tetris/rulesets/ruleset.lua @@ -115,8 +115,8 @@ function Ruleset:attemptRotate(new_inputs, piece, grid, initial) local new_piece = piece:withRelativeRotation(rot_dir) if (grid:canPlacePiece(new_piece)) then - piece:setRelativeRotation(rot_dir) self:onPieceRotate(piece, grid) + piece:setRelativeRotation(rot_dir) else if not(initial and self.enable_IRS_wallkicks == false) then self:attemptWallkicks(piece, new_piece, rot_dir, grid) diff --git a/tetris/rulesets/standard_exp.lua b/tetris/rulesets/standard_exp.lua index a4975ba..029dc85 100755 --- a/tetris/rulesets/standard_exp.lua +++ b/tetris/rulesets/standard_exp.lua @@ -1,136 +1,13 @@ local Piece = require 'tetris.components.piece' -local Ruleset = require 'tetris.rulesets.ruleset' +local Ruleset = require 'tetris.rulesets.arika_srs' local SRS = Ruleset:extend() SRS.name = "Guideline SRS" SRS.hash = "Standard" -SRS.world = true -SRS.colourscheme = { - I = "C", - L = "O", - J = "B", - S = "G", - Z = "R", - O = "Y", - T = "M", -} -SRS.softdrop_lock = false -SRS.harddrop_lock = true SRS.enable_IRS_wallkicks = true -SRS.spawn_positions = { - I = { x=5, y=2 }, - J = { x=4, y=3 }, - L = { x=4, y=3 }, - O = { x=5, y=3 }, - S = { x=4, y=3 }, - T = { x=4, y=3 }, - Z = { x=4, y=3 }, -} - -SRS.big_spawn_positions = { - I = { x=3, y=0 }, - J = { x=2, y=1 }, - L = { x=2, y=1 }, - O = { x=3, y=1 }, - S = { x=2, y=1 }, - T = { x=2, y=1 }, - Z = { x=2, y=1 }, -} - -SRS.block_offsets = { - I={ - { {x=0, y=0}, {x=-1, y=0}, {x=-2, y=0}, {x=1, y=0} }, - { {x=0, y=0}, {x=0, y=-1}, {x=0, y=1}, {x=0, y=2} }, - { {x=0, y=1}, {x=-1, y=1}, {x=-2, y=1}, {x=1, y=1} }, - { {x=-1, y=0}, {x=-1, y=-1}, {x=-1, y=1}, {x=-1, y=2} }, - }, - J={ - { {x=0, y=0}, {x=-1, y=0}, {x=1, y=0}, {x=-1, y=-1} }, - { {x=0, y=0}, {x=0, y=-1}, {x=0, y=1} , {x=1, y=-1} }, - { {x=0, y=0}, {x=1, y=0}, {x=-1, y=0}, {x=1, y=1} }, - { {x=0, y=0}, {x=0, y=1}, {x=0, y=-1}, {x=-1, y=1} }, - }, - L={ - { {x=0, y=0}, {x=-1, y=0}, {x=1, y=0}, {x=1, y=-1} }, - { {x=0, y=0}, {x=0, y=-1}, {x=0, y=1}, {x=1, y=1} }, - { {x=0, y=0}, {x=1, y=0}, {x=-1, y=0}, {x=-1, y=1} }, - { {x=0, y=0}, {x=0, y=1}, {x=0, y=-1}, {x=-1, y=-1} }, - }, - O={ - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - { {x=0, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1} }, - }, - S={ - { {x=1, y=-1}, {x=0, y=-1}, {x=0, y=0}, {x=-1, y=0} }, - { {x=1, y=1}, {x=1, y=0}, {x=0, y=0}, {x=0, y=-1} }, - { {x=-1, y=1}, {x=0, y=1}, {x=0, y=0}, {x=1, y=0} }, - { {x=-1, y=-1}, {x=-1, y=0}, {x=0, y=0}, {x=0, y=1} }, - }, - T={ - { {x=0, y=0}, {x=-1, y=0}, {x=1, y=0}, {x=0, y=-1} }, - { {x=0, y=0}, {x=0, y=-1}, {x=0, y=1}, {x=1, y=0} }, - { {x=0, y=0}, {x=1, y=0}, {x=-1, y=0}, {x=0, y=1} }, - { {x=0, y=0}, {x=0, y=1}, {x=0, y=-1}, {x=-1, y=0} }, - }, - Z={ - { {x=-1, y=-1}, {x=0, y=-1}, {x=0, y=0}, {x=1, y=0} }, - { {x=1, y=-1}, {x=1, y=0}, {x=0, y=0}, {x=0, y=1} }, - { {x=1, y=1}, {x=0, y=1}, {x=0, y=0}, {x=-1, y=0} }, - { {x=-1, y=1}, {x=-1, y=0}, {x=0, y=0}, {x=0, y=-1} }, - } -} - -SRS.wallkicks_3x3 = { - [0]={ - [1]={{x=-1, y=0}, {x=-1, y=-1}, {x=0, y=2}, {x=-1, y=2}}, - [2]={{x=0, y=1}, {x=0, y=-1}}, - [3]={{x=1, y=0}, {x=1, y=-1}, {x=0, y=2}, {x=1, y=2}}, - }, - [1]={ - [0]={{x=1, y=0}, {x=1, y=1}, {x=0, y=-2}, {x=1, y=-2}}, - [2]={{x=1, y=0}, {x=1, y=1}, {x=0, y=-2}, {x=1, y=-2}}, - [3]={{x=0, y=1}, {x=0, y=-1}}, - }, - [2]={ - [0]={{x=0, y=1}, {x=0, y=-1}}, - [1]={{x=-1, y=0}, {x=-1, y=-1}, {x=0, y=2}, {x=-1, y=2}}, - [3]={{x=1, y=0}, {x=1, y=-1}, {x=0, y=2}, {x=1, y=2}}, - }, - [3]={ - [0]={{x=-1, y=0}, {x=-1, y=1}, {x=0, y=-2}, {x=-1, y=-2}}, - [1]={{x=0, y=1}, {x=0, y=-1}}, - [2]={{x=-1, y=0}, {x=-1, y=1}, {x=0, y=-2}, {x=-1, y=-2}}, - }, -}; - -SRS.wallkicks_line = { - [0]={ - [1]={{x=-2, y=0}, {x=1, y=0}, {x=-2, y=1}, {x=1, y=-2}}, - [2]={}, - [3]={{x=-1, y=0}, {x=2, y=0}, {x=-1, y=-2}, {x=2, y=1}}, - }, - [1]={ - [0]={{x=2, y=0}, {x=-1, y=0}, {x=2, y=-1}, {x=-1, y=2}}, - [2]={{x=-1, y=0}, {x=2, y=0}, {x=-1, y=-2}, {x=2, y=1}}, - [3]={{x=0, y=1}, {x=0, y=-1}, {x=0, y=2}, {x=0, y=-2}}, - }, - [2]={ - [0]={}, - [1]={{x=1, y=0}, {x=-2, y=0}, {x=1, y=2}, {x=-2, y=-1}}, - [3]={{x=2, y=0}, {x=-1, y=0}, {x=2, y=-1}, {x=-1, y=2}}, - }, - [3]={ - [0]={{x=1, y=0}, {x=-2, y=0}, {x=1, y=2}, {x=-2, y=-1}}, - [1]={{x=0, y=1}, {x=0, y=-1}, {x=0, y=2}, {x=0, y=-2}}, - [2]={{x=-2, y=0}, {x=1, y=0}, {x=-2, y=1}, {x=1, y=-2}}, - }, -}; - function SRS:check_new_low(piece) for _, block in pairs(piece:getBlockOffsets()) do local y = piece.position.y + block.y @@ -141,33 +18,6 @@ function SRS:check_new_low(piece) end end --- Component functions. - -function SRS:attemptWallkicks(piece, new_piece, rot_dir, grid) - - local kicks - if piece.shape == "O" then - return - elseif piece.shape == "I" then - kicks = SRS.wallkicks_line[piece.rotation][new_piece.rotation] - else - kicks = SRS.wallkicks_3x3[piece.rotation][new_piece.rotation] - end - - assert(piece.rotation ~= new_piece.rotation) - - for idx, offset in pairs(kicks) do - kicked_piece = new_piece:withOffset(offset) - if grid:canPlacePiece(kicked_piece) then - self:onPieceRotate(piece, grid) - piece:setRelativeRotation(rot_dir) - piece:setOffset(offset) - return - end - end - -end - function SRS:onPieceCreate(piece, grid) piece.manipulations = 0 piece.lowest_y = -math.huge