调整ai尤其是cc相关代码,捕获窒息的时候可能会有实心行错误并让cc进入自杀模式
This commit is contained in:
34
parts/ai.lua
34
parts/ai.lua
@@ -37,24 +37,43 @@ if type(_CC)=='table'then
|
|||||||
}
|
}
|
||||||
local CC=CC
|
local CC=CC
|
||||||
function CC.updateField(P)
|
function CC.updateField(P)
|
||||||
|
if not P.AI_thread then return end
|
||||||
local F,n={},1
|
local F,n={},1
|
||||||
for y=1,min(#P.field,40)do
|
local field=P.field
|
||||||
|
for y=1,min(#field,40)do
|
||||||
|
local sum=0
|
||||||
for x=1,10 do
|
for x=1,10 do
|
||||||
F[n]=P.field[y][x]>0
|
if field[y][x]>0 then
|
||||||
|
F[n]=true
|
||||||
|
sum=sum+1
|
||||||
|
else
|
||||||
|
F[n]=false
|
||||||
|
end
|
||||||
n=n+1
|
n=n+1
|
||||||
end
|
end
|
||||||
|
if sum==10 then
|
||||||
|
--[[
|
||||||
|
--Print field and crash the game
|
||||||
|
for i=24,0,-1 do
|
||||||
|
local l=""for j=1,10 do l=l..(F[10*i+j]and"X"or"_")end print(l)
|
||||||
|
end
|
||||||
|
error("Row "..y.." full")
|
||||||
|
]]
|
||||||
|
P.AI_thread=nil
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
while n<=400 do
|
while n<=400 do
|
||||||
F[n]=false
|
F[n]=false
|
||||||
n=n+1
|
n=n+1
|
||||||
end
|
end
|
||||||
if not pcall(CC.update,P.AI_bot,F,P.b2b>=100,P.combo)then
|
if not pcall(CC.update,P.AI_bot,F,P.b2b>=100,P.combo)then
|
||||||
P.AI_bot=nil
|
P.AI_thread=nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function CC.switch20G(P)
|
function CC.switch20G(P)
|
||||||
if not pcall(CC.destroy,P.AI_bot)then
|
if not pcall(CC.destroy,P.AI_bot)then
|
||||||
P.AI_bot=nil
|
P.AI_thread=nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
P.AIdata._20G=true
|
P.AIdata._20G=true
|
||||||
@@ -281,20 +300,19 @@ return{
|
|||||||
while true do
|
while true do
|
||||||
--Start thinking
|
--Start thinking
|
||||||
yield()
|
yield()
|
||||||
|
if not P.AI_bot then break end
|
||||||
if not pcall(CC.think,P.AI_bot)then break end
|
if not pcall(CC.think,P.AI_bot)then break end
|
||||||
|
|
||||||
--Poll keys
|
--Poll keys
|
||||||
local success,result,dest,hold,move
|
local success,result,dest,hold,move
|
||||||
repeat
|
repeat
|
||||||
yield()
|
yield()
|
||||||
|
if not P.AI_bot then break end
|
||||||
success,result,dest,hold,move=pcall(CC.getMove,P.AI_bot)
|
success,result,dest,hold,move=pcall(CC.getMove,P.AI_bot)
|
||||||
until not success or result==0 or result==2
|
until not success or result==0 or result==2
|
||||||
if not success then break end
|
if not success then break end
|
||||||
if result==2 then
|
if result==2 then
|
||||||
while true do
|
break
|
||||||
yield()
|
|
||||||
ins(keys,6)
|
|
||||||
end
|
|
||||||
elseif result==0 then
|
elseif result==0 then
|
||||||
dest[5],dest[6]=dest[1][1],dest[1][2]
|
dest[5],dest[6]=dest[1][1],dest[1][2]
|
||||||
dest[7],dest[8]=dest[2][1],dest[2][2]
|
dest[7],dest[8]=dest[2][1],dest[2][2]
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ function Player:garbageRelease()--Check garbage buffer and try to release them
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if flag and self.AI_mode=='CC'and self.AI_bot then CC.updateField(self)end
|
if flag and self.AI_mode=='CC'then CC.updateField(self)end
|
||||||
end
|
end
|
||||||
function Player:garbageRise(color,amount,line)--Release n-lines garbage to field
|
function Player:garbageRise(color,amount,line)--Release n-lines garbage to field
|
||||||
local _
|
local _
|
||||||
@@ -518,32 +518,45 @@ function Player:freshBlock(mode)--string mode: push/move/fresh/newBlock
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function Player:lock()
|
function Player:lock()
|
||||||
local dest=self.AI_dest
|
if self.AI_dest then
|
||||||
local has_dest=dest~=nil
|
local dest=self.AI_dest
|
||||||
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
|
||||||
if dest then
|
|
||||||
local x=self.curX+j-1
|
local x=self.curX+j-1
|
||||||
for k=1,#dest,2 do
|
if dest then
|
||||||
if x==dest[k]+1 and y==dest[k+1]+1 then
|
for k=1,#dest,2 do
|
||||||
rem(dest,k)rem(dest,k)
|
if x==dest[k]+1 and y==dest[k+1]+1 then
|
||||||
goto BREAK_success
|
rem(dest,k)rem(dest,k)
|
||||||
|
goto BREAK_success
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
dest=nil
|
||||||
|
::BREAK_success::
|
||||||
end
|
end
|
||||||
dest=nil
|
|
||||||
::BREAK_success::
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
if not dest and self.AI_mode=='CC'then
|
||||||
if has_dest and not dest and self.AI_mode=='CC'and self.AI_bot then
|
CC.updateField(self)
|
||||||
CC.updateField(self)
|
end
|
||||||
|
else
|
||||||
|
local CB=self.cur.bk
|
||||||
|
for i=1,#CB do
|
||||||
|
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
|
||||||
|
for j=1,#CB[1]do
|
||||||
|
if CB[i][j]then
|
||||||
|
self.field[y][self.curX+j-1]=self.cur.color
|
||||||
|
self.visTime[y][self.curX+j-1]=self.showTime
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -187,16 +187,20 @@ function update.alive(P,dt)
|
|||||||
local C=P.AI_keys
|
local C=P.AI_keys
|
||||||
P.AI_delay=P.AI_delay-1
|
P.AI_delay=P.AI_delay-1
|
||||||
if not C[1]then
|
if not C[1]then
|
||||||
if P.AI_thread and not pcall(P.AI_thread)then
|
if P.AI_thread then
|
||||||
P.AI_thread=false
|
if not pcall(P.AI_thread)then
|
||||||
|
P.AI_thread=nil
|
||||||
|
end
|
||||||
|
else
|
||||||
|
P:act_hardDrop()
|
||||||
end
|
end
|
||||||
elseif P.AI_delay<=0 then
|
elseif P.AI_delay<=0 then
|
||||||
P:pressKey(C[1])P:releaseKey(C[1])
|
|
||||||
if P.AI_mode~='CC'or C[1]>3 then
|
if P.AI_mode~='CC'or C[1]>3 then
|
||||||
P.AI_delay=P.AI_delay0*2
|
P.AI_delay=P.AI_delay0*2
|
||||||
else
|
else
|
||||||
P.AI_delay=P.AI_delay0*.5
|
P.AI_delay=P.AI_delay0*.5
|
||||||
end
|
end
|
||||||
|
P:pressKey(C[1])P:releaseKey(C[1])
|
||||||
rem(C,1)
|
rem(C,1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user