2020-12-02 23:26:36 -06:00
|
|
|
local Piece = require 'tetris.components.piece'
|
2022-10-24 19:09:08 -05:00
|
|
|
local Ruleset = require 'tetris.rulesets.standard_ace'
|
2020-12-02 23:26:36 -06:00
|
|
|
|
|
|
|
local SRS = Ruleset:extend()
|
|
|
|
|
|
|
|
SRS.name = "Guideline SRS"
|
|
|
|
SRS.hash = "Standard"
|
|
|
|
SRS.softdrop_lock = false
|
|
|
|
SRS.harddrop_lock = true
|
|
|
|
|
2023-07-04 01:27:04 -05:00
|
|
|
SRS.enable_IRS_wallkicks = true
|
|
|
|
|
2021-01-28 20:05:36 -06:00
|
|
|
SRS.MANIPULATIONS_MAX = 15
|
2020-12-02 23:26:36 -06:00
|
|
|
|
2021-01-30 21:28:34 -06:00
|
|
|
SRS.wallkicks_line = {
|
|
|
|
[0]={
|
|
|
|
[1]={{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=0},{x=2,y=0},{x=0,y=1}},
|
|
|
|
[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=2},{x=0,y=-1},{x=0,y=-2},{x=-1,y=0}},
|
|
|
|
},
|
|
|
|
[2]={
|
|
|
|
[0]={{x=1,y=0},{x=2,y=0},{x=-1,y=0},{x=-2,y=0},{x=0,y=-1}},
|
|
|
|
[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=2},{x=0,y=-1},{x=0,y=-2},{x=1,y=0}},
|
|
|
|
[2]={{x=-2, y=0}, {x=1, y=0}, {x=-2, y=1}, {x=1, y=-2}},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-10-24 19:09:08 -05:00
|
|
|
function SRS:attemptWallkicks(piece, new_piece, rot_dir, grid)
|
2021-01-30 21:28:34 -06:00
|
|
|
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
|
|
|
|
piece:setRelativeRotation(rot_dir)
|
|
|
|
piece:setOffset(offset)
|
|
|
|
self:onPieceRotate(piece, grid)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2021-01-30 15:49:52 -06:00
|
|
|
function SRS:checkNewLow(piece)
|
|
|
|
for _, block in pairs(piece:getBlockOffsets()) do
|
|
|
|
local y = piece.position.y + block.y
|
|
|
|
if y > piece.lowest_y then
|
|
|
|
piece.manipulations = 0
|
|
|
|
piece.rotations = 0
|
|
|
|
piece.lowest_y = y
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-24 19:09:08 -05:00
|
|
|
function SRS:onPieceCreate(piece, grid)
|
|
|
|
piece.manipulations = 0
|
|
|
|
piece.rotations = 0
|
|
|
|
piece.lowest_y = -math.huge
|
|
|
|
end
|
|
|
|
|
2021-01-28 20:19:47 -06:00
|
|
|
function SRS:onPieceDrop(piece, grid)
|
|
|
|
self:checkNewLow(piece)
|
|
|
|
if piece.manipulations >= self.MANIPULATIONS_MAX and piece:isDropBlocked(grid) then
|
|
|
|
piece.locked = true
|
|
|
|
else
|
|
|
|
piece.lock_delay = 0 -- step reset
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SRS:onPieceMove(piece, grid)
|
|
|
|
piece.lock_delay = 0 -- move reset
|
|
|
|
if piece:isDropBlocked(grid) then
|
|
|
|
piece.manipulations = piece.manipulations + 1
|
|
|
|
if piece.manipulations >= SRS.MANIPULATIONS_MAX then
|
|
|
|
piece.locked = true
|
|
|
|
end
|
2023-10-19 02:33:25 -05:00
|
|
|
else
|
|
|
|
piece.locked = false
|
2021-01-28 20:19:47 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-02 23:26:36 -06:00
|
|
|
function SRS:onPieceRotate(piece, grid)
|
|
|
|
piece.lock_delay = 0 -- rotate reset
|
2021-01-28 20:15:04 -06:00
|
|
|
self:checkNewLow(piece)
|
2020-12-02 23:26:36 -06:00
|
|
|
piece.manipulations = piece.manipulations + 1
|
2021-02-17 13:48:35 -06:00
|
|
|
if piece.manipulations >= self.MANIPULATIONS_MAX then
|
|
|
|
piece:moveInGrid({ x = 0, y = 1 }, 1, grid)
|
|
|
|
if piece:isDropBlocked(grid) then
|
|
|
|
piece.locked = true
|
|
|
|
end
|
|
|
|
end
|
2020-12-02 23:26:36 -06:00
|
|
|
end
|
|
|
|
|
2021-02-17 13:52:05 -06:00
|
|
|
function SRS:canPieceRotate() return true end
|
2021-02-17 13:48:35 -06:00
|
|
|
|
2023-07-04 01:27:04 -05:00
|
|
|
function SRS:get180RotationValue() return 2 end
|
|
|
|
|
2020-12-02 23:26:36 -06:00
|
|
|
return SRS
|