Added Autopilot-I, fixed BONKERS

pull/4/head
Ishaan Bhardwaj 2021-05-28 10:11:01 -04:00
parent 7f0d0ef2e6
commit 71f1d4ce32
2 changed files with 51 additions and 1 deletions

View File

@ -0,0 +1,50 @@
local ARS = require 'tetris.rulesets.arika'
local Autopilot = ARS:extend()
Autopilot.name = "Autopilot-I"
Autopilot.hash = "Autopilot"
function Autopilot:attemptRotate(new_inputs, piece, grid, initial)
local rot_dir = 0
if (new_inputs["rotate_left"] or new_inputs["rotate_left2"]) then
rot_dir = 3
elseif (new_inputs["rotate_right"] or new_inputs["rotate_right2"]) then
rot_dir = 1
elseif (new_inputs["rotate_180"]) then
rot_dir = self:get180RotationValue()
end
if rot_dir == 0 then return end
if config.gamesettings.world_reverse == 3 or (self.world and config.gamesettings.world_reverse == 2) then
rot_dir = 4 - rot_dir
end
local new_piece = piece:withRelativeRotation(rot_dir)
if self:attemptWallkicks(piece, new_piece, rot_dir, grid) then
return
elseif grid:canPlacePiece(new_piece) then
piece:setRelativeRotation(rot_dir)
self:onPieceRotate(piece, grid)
end
end
function Autopilot:attemptWallkicks(piece, new_piece, rot_dir, grid)
for y = grid.height, -grid.height, -1 do
for x = -grid.width, grid.width do
kicked_piece = piece:withOffset({x=x, y=y})
kicked_piece.shape = "I"
kicked_piece.rotation = 1
if grid:canPlacePiece(kicked_piece) then
piece:setOffset({x=x, y=y})
piece.shape = "I"
piece.rotation = 1
return true
end
end
end
end
return Autopilot

View File

@ -127,7 +127,7 @@ function BONKERS:attemptWallkicks(piece, new_piece, rot_dir, grid)
horizontal_kicks = {0, 1, -1}
end
for y_offset = 24, -24, -1 do
for y_offset = grid.height, -grid.height, -1 do
for idx, x_offset in pairs(horizontal_kicks) do
local offset = {x=x_offset, y=y_offset}
kicked_piece = new_piece:withOffset(offset)