2020-10-05 10:52:37 -05:00
|
|
|
local Piece = require 'tetris.components.piece'
|
|
|
|
local Ruleset = require 'tetris.rulesets.ruleset'
|
|
|
|
|
|
|
|
local ARS = Ruleset:extend()
|
|
|
|
|
|
|
|
ARS.name = "ACE-ARS"
|
|
|
|
ARS.hash = "ArikaACE"
|
|
|
|
|
2020-10-16 21:37:44 -05:00
|
|
|
ARS.colourscheme = {
|
2020-11-06 19:49:44 -06:00
|
|
|
I = "C",
|
|
|
|
L = "O",
|
|
|
|
J = "B",
|
|
|
|
S = "G",
|
|
|
|
Z = "R",
|
|
|
|
O = "Y",
|
|
|
|
T = "M",
|
2020-10-16 21:37:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ARS.softdrop_lock = false
|
|
|
|
ARS.harddrop_lock = true
|
|
|
|
|
2020-10-05 10:52:37 -05:00
|
|
|
ARS.spawn_positions = {
|
2020-10-05 21:17:15 -05:00
|
|
|
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 },
|
2020-10-05 10:52:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ARS.big_spawn_positions = {
|
2020-10-13 14:26:07 -05:00
|
|
|
I = { x=3, y=0 },
|
2020-10-06 15:27:28 -05:00
|
|
|
J = { x=2, y=1 },
|
|
|
|
L = { x=2, y=1 },
|
2020-10-13 14:26:07 -05:00
|
|
|
O = { x=3, y=1 },
|
2020-10-06 15:27:28 -05:00
|
|
|
S = { x=2, y=1 },
|
|
|
|
T = { x=2, y=1 },
|
|
|
|
Z = { x=2, y=1 },
|
2020-10-05 10:52:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2020-10-07 13:54:18 -05:00
|
|
|
) then
|
2020-11-06 19:49:44 -06:00
|
|
|
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
|
2020-10-05 10:52:37 -05:00
|
|
|
|
|
|
|
if piece.shape == "I" then
|
|
|
|
-- special kick rules for I
|
2020-11-21 22:29:06 -06:00
|
|
|
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
|
2020-10-05 10:52:37 -05:00
|
|
|
-- 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
|
2020-10-07 13:54:18 -05:00
|
|
|
else
|
2020-11-06 19:49:44 -06:00
|
|
|
-- 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
|
2020-10-05 10:52:37 -05:00
|
|
|
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
|
2020-11-21 20:48:45 -06:00
|
|
|
if piece.floorkick >= 2 and piece:isDropBlocked(grid) then
|
|
|
|
piece.locked = true
|
|
|
|
end
|
2020-10-05 10:52:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function ARS:onPieceMove(piece, grid)
|
|
|
|
piece.lock_delay = 0 -- move reset
|
|
|
|
if piece:isDropBlocked(grid) then
|
|
|
|
piece.manipulations = piece.manipulations + 1
|
2020-11-21 20:48:45 -06:00
|
|
|
if piece.manipulations >= 128 then
|
2020-10-05 10:52:37 -05:00
|
|
|
piece.locked = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ARS:onPieceRotate(piece, grid)
|
|
|
|
piece.lock_delay = 0 -- rotate reset
|
|
|
|
if piece:isDropBlocked(grid) then
|
|
|
|
piece.manipulations = piece.manipulations + 1
|
2020-11-21 20:48:45 -06:00
|
|
|
if piece.manipulations >= 128 then
|
2020-10-05 10:52:37 -05:00
|
|
|
piece.locked = true
|
|
|
|
end
|
|
|
|
end
|
2020-11-21 20:48:45 -06:00
|
|
|
if piece.floorkick >= 1 then
|
|
|
|
piece.floorkick = piece.floorkick + 1
|
|
|
|
end
|
2020-10-05 10:52:37 -05:00
|
|
|
end
|
|
|
|
|
2020-11-06 18:17:32 -06:00
|
|
|
function ARS:get180RotationValue()
|
|
|
|
if config.gamesettings.world_reverse == 3 then
|
|
|
|
return 1
|
2020-11-14 18:20:25 -06:00
|
|
|
else
|
|
|
|
return 3
|
2020-11-06 18:17:32 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-05 10:52:37 -05:00
|
|
|
function ARS:getDefaultOrientation() return 3 end -- downward facing pieces by default
|
|
|
|
|
|
|
|
return ARS
|