把检测ai是否放到目标位置的代码独立出玩家lock方法,略微提升性能

This commit is contained in:
MrZ626
2021-08-22 15:35:40 +08:00
parent 36c11961b6
commit cc23869128

View File

@@ -517,44 +517,30 @@ function Player:freshBlock(mode)--string mode: push/move/fresh/newBlock
end end
end end
end end
function Player:lock() function Player:checkAIdest()
if self.AI_dest then if not self.AI_dest then return end
local dest=self.AI_dest local dest=self.AI_dest
local CB=self.cur.bk local CB=self.cur.bk
for i=1,#CB do for k=1,#dest,2 do
local y=self.curY+i-1 local r=CB[dest[k+1]-self.curY+2]
if not self.field[y]then self.field[y],self.visTime[y]=FREEROW.get(0),FREEROW.get(0)end if not r or not r[dest[k]-self.curX+2]then
for j=1,#CB[1]do if self.AI_mode=='CC'then
if CB[i][j]then CC.updateField(self)
self.field[y][self.curX+j-1]=self.cur.color
self.visTime[y][self.curX+j-1]=self.showTime
local x=self.curX+j-1
if dest then
for k=1,#dest,2 do
if x==dest[k]+1 and y==dest[k+1]+1 then
rem(dest,k)rem(dest,k)
goto BREAK_success
end
end
dest=nil
::BREAK_success::
end
end
end end
self.AI_dest=nil
return
end end
if not dest and self.AI_mode=='CC'then end
CC.updateField(self) end
end function Player:lock()
else local CB=self.cur.bk
local CB=self.cur.bk for i=1,#CB do
for i=1,#CB do local y=self.curY+i-1
local y=self.curY+i-1 if not self.field[y]then self.field[y],self.visTime[y]=FREEROW.get(0),FREEROW.get(0)end
if not self.field[y]then self.field[y],self.visTime[y]=FREEROW.get(0),FREEROW.get(0)end for j=1,#CB[1]do
for j=1,#CB[1]do if CB[i][j]then
if CB[i][j]then self.field[y][self.curX+j-1]=self.cur.color
self.field[y][self.curX+j-1]=self.cur.color self.visTime[y][self.curX+j-1]=self.showTime
self.visTime[y][self.curX+j-1]=self.showTime
end
end end
end end
end end
@@ -1098,7 +1084,7 @@ do--Player.drop(self)--Place piece
dospin=dospin+2 dospin=dospin+2
end end
--Lock block to field self:checkAIdest()
self:lock() self:lock()
--Clear list of cleared-rows --Clear list of cleared-rows