整理代码,删掉三处goto

This commit is contained in:
MrZ626
2021-03-25 10:20:18 +08:00
parent 390d2a42b8
commit 053a5a55e6
3 changed files with 69 additions and 91 deletions

View File

@@ -1,4 +1,4 @@
local min=math.min local ins=table.insert
return{ return{
color=COLOR.red, color=COLOR.red,
env={ env={
@@ -26,69 +26,52 @@ return{
end end
height[11]=999 height[11]=999
local res={1,1,2,2,3,4} local wei={1,1,2,2,3,4}
local d=0 local d=0
local A
for i=1,10 do for i=1,10 do
d=d+height[i] d=d+height[i]
end end
if d<40 or P.stat.row>2*42 then if d<40 or P.stat.row>2*42 then--Low field or almost win, give SZO
A=#res+1
for _=1,4 do for _=1,4 do
res[A]=1 ins(wei,1)
res[A+1]=2 ins(wei,2)
res[A+2]=6 ins(wei,6)
A=A+3
end end
goto END else
end --Give I when no hole
local tempDeltaHei=-999--Height difference
--Give I when no hole for x=2,11 do
d=-999--Height difference local deltaHei=height[x]-height[x-1]
--A=hole mark if tempDeltaHei<-2 and deltaHei>2 then
for x=2,11 do break
local _=height[x]-height[x-1] elseif x==11 then
if d<-2 and _>2 then for _=1,3 do ins(wei,7)end
A=true else
tempDeltaHei=deltaHei
end
end end
d=_
end
if not A then
A=#res+1
res[A]=7
res[A+1]=7
res[A+2]=7
end
--Give O when no d=0/give T when no d=1 --Give O when no d=0/give T when no d=1
d=0--d=0 count local flatCount=0--d=0 count
A=0--d=1 count local stairCount=0--d=1 count
for x=2,10 do for x=2,10 do
local _=height[x]-height[x-1] local _=height[x]-height[x-1]
if _==0 then if _==0 then
d=d+1 flatCount=flatCount+1
elseif _==1 or _==-1 then elseif _==1 or _==-1 then
A=A+1 stairCount=stairCount+1
end
end
if flatCount<3 then
for _=1,3 do ins(wei,6)end
end
if stairCount<3 then
for _=1,4 do ins(wei,5)end
end end
end end
if d<3 then
A=#res+1
res[A]=6
res[A+1]=6
res[A+2]=6
end
if A<3 then
A=#res+1
res[A]=5
res[A+1]=5
res[A+2]=5
res[A+3]=5
res[A+4]=5
end
::END::
FREEROW.discard(height) FREEROW.discard(height)
P:getNext(res[P:RND(#res)]) P:getNext(wei[P:RND(#wei)])
end end
end end
end, end,
@@ -107,7 +90,7 @@ return{
local R=100-P.stat.row local R=100-P.stat.row
mStr(R>=0 and R or 0,69,265) mStr(R>=0 and R or 0,69,265)
end, end,
score=function(P)return{min(P.stat.row,100),P.stat.time}end, score=function(P)return{math.min(P.stat.row,100),P.stat.time}end,
scoreDisp=function(D)return D[1].." Lines "..TIMESTR(D[2])end, scoreDisp=function(D)return D[1].." Lines "..TIMESTR(D[2])end,
comp=function(a,b)return a[1]>b[1]or a[1]==b[1]and a[2]<b[2]end, comp=function(a,b)return a[1]>b[1]or a[1]==b[1]and a[2]<b[2]end,
getRank=function(P) getRank=function(P)

View File

@@ -618,6 +618,10 @@ function Player.spin(P,d,ifpre)
SFX.fieldPlay(ifpre and"prerotate"or"rotate",nil,P) SFX.fieldPlay(ifpre and"prerotate"or"rotate",nil,P)
end end
end end
local phyHoldKickX={
[true]={0,-1,1},--X==?.0 tests
[false]={-.5,.5},--X==?.5 tests
}
function Player.hold(P,ifpre) function Player.hold(P,ifpre)
local ENV=P.gameEnv local ENV=P.gameEnv
if P.holdTime>0 and(ifpre or P.waiting==-1)then if P.holdTime>0 and(ifpre or P.waiting==-1)then
@@ -638,44 +642,34 @@ function Player.hold(P,ifpre)
end end
if ENV.phyHold and C and not ifpre then--Physical hold if ENV.phyHold and C and not ifpre then--Physical hold
local success
local x,y=P.curX,P.curY local x,y=P.curX,P.curY
x=x+(#C.bk[1]-#H.bk[1])*.5 x=x+(#C.bk[1]-#H.bk[1])*.5
y=y+(#C.bk-#H.bk)*.5 y=y+(#C.bk-#H.bk)*.5
local iki=phyHoldKickX[x==int(x)]
for Y=int(y),ceil(y+.5)do for Y=int(y),ceil(y+.5)do
local X=x for i=1,#iki do
while true do local X=x+iki[i]
X=int(X)
if not P:ifoverlap(H.bk,X,Y)then if not P:ifoverlap(H.bk,X,Y)then
x,y=X,Y x,y=X,Y
success=true goto BREAK_success
goto BREAK
end
if X==x then
X=X-1
elseif X<x then
X=2*x-X
else
break
end end
end end
end end
::BREAK:: --<for-else> All test failed, interrupt with sound
if success then
P.spinLast=false
P.spinSeq=0
local hb=P:getBlock(C.id)
hb.name=C.name
hb.color=C.color
ins(P.holdQueue,hb)
P.cur=rem(P.holdQueue,1)
P.curX,P.curY=x,y
else
SFX.play("finesseError") SFX.play("finesseError")
return do return end
end --<for-end>
::BREAK_success::
P.spinLast=false
P.spinSeq=0
local hb=P:getBlock(C.id)
hb.name=C.name
hb.color=C.color
ins(P.holdQueue,hb)
P.cur=rem(P.holdQueue,1)
P.curX,P.curY=x,y
else--Normal hold else--Normal hold
P.spinLast=false P.spinLast=false
P.spinSeq=0 P.spinSeq=0

View File

@@ -125,37 +125,38 @@ local function freshMaxTile()
end end
local function squash(L) local function squash(L)
local p1,p2=1 local p1,p2=1
local moved local moved=false
while p1<4 do while true do
p2=p1+1 p2=p1+1
while not L[p2]do while not L[p2]do
p2=p2+1 p2=p2+1
if p2==5 then if p2==5 then
p1=p1+1 p1=p1+1
goto continue if p1==4 then
return L[1],L[2],L[3],L[4],moved
end
break
end end
end end
if not L[p1]then--air←2 if not L[p1]then--air←2
L[p1]=L[p2] L[p1],L[p2]=L[p2],false
moved=true moved=true
elseif L[p1]==L[p2]then--2←2 elseif L[p1]==L[p2]then--2←2
L[p1]=L[p1]+1 L[p1],L[p2]=L[p1]+1,false
if L[p1]>maxTile then if L[p1]>maxTile then
freshMaxTile() freshMaxTile()
end end
moved=true L[p2]=false
p1=p1+1 p1=p1+1
moved=true
elseif p1+1~=p2 then--2←4 elseif p1+1~=p2 then--2←4
L[p1+1]=L[p2] L[p1+1],L[p2]=L[p2],false
moved=true
p1=p1+1 p1=p1+1
moved=true
else--2,4 else--2,4
p1=p1+1 p1=p1+1
end end
if moved then L[p2]=false end
::continue::
end end
return L[1],L[2],L[3],L[4],moved
end end
local function reset() local function reset()
for i=1,16 do board[i]=false end for i=1,16 do board[i]=false end