forked from pyrex/chameleonic
_calc_push golf redux
Removed unnecessary variable declarations and conditional cases by using an "assume, alternate, verify assumption" pattern and reusing ax0/ay0 when they would never be referenced again.
This commit is contained in:
parent
cb36faac23
commit
b2dbd9ec60
@ -1645,21 +1645,16 @@ function rope:_calc_push(
|
|||||||
smy=-smy
|
smy=-smy
|
||||||
end
|
end
|
||||||
|
|
||||||
local mx,dmx
|
local dmx=1 -- maybe push right?
|
||||||
if anch.adx==-1 and a0.x>an.x+7 then
|
if anch.adx==-1 and a0.x>an.x+7 then
|
||||||
-- push left
|
-- push left
|
||||||
mx=ax0-1
|
ax0, dmx=ax0-1,-1
|
||||||
dmx=-1
|
elseif anch.adx!=1 or a0.x>=an.x-7 then
|
||||||
elseif anch.adx==1 and a0.x<an.x-7 then
|
|
||||||
-- push right
|
|
||||||
mx=ax0
|
|
||||||
dmx=1
|
|
||||||
else
|
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|
||||||
for my=my0,my1,smy do
|
for my=my0,my1,smy do
|
||||||
add(ops,{mx,my,dmx,0})
|
add(ops,{ax0,my,dmx,0})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1671,22 +1666,16 @@ function rope:_calc_push(
|
|||||||
smx=-smx
|
smx=-smx
|
||||||
end
|
end
|
||||||
|
|
||||||
local my,dmy
|
local dmy=1 -- maybe push down?
|
||||||
if anch.ady==-1 and a0.y>an.y+6 then
|
if anch.ady==-1 and a0.y>an.y+6 then
|
||||||
-- push up
|
-- push up
|
||||||
my=ay0-1
|
ay0,dmy=ay0-1,dmy=-1
|
||||||
dmy=-1
|
elseif anch.ady!=1 or a0.y>=an.y-6 then
|
||||||
|
|
||||||
elseif anch.ady==1 and a0.y<an.y-6 then
|
|
||||||
-- push down
|
|
||||||
my=ay0
|
|
||||||
dmy=1
|
|
||||||
else
|
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|
||||||
for mx=mx0,mx1,smx do
|
for mx=mx0,mx1,smx do
|
||||||
add(ops,{mx,my,0,dmy})
|
add(ops,{mx,ay0,0,dmy})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user