ai协程化

This commit is contained in:
MrZ626
2021-03-05 15:28:43 +08:00
parent 640403866f
commit 15ecee6767
3 changed files with 66 additions and 71 deletions

View File

@@ -1424,7 +1424,6 @@ do--Player.drop(P)--Place piece
end
function Player.loadAI(P,data)--Load AI params
P.AI_mode=data.type
P.AI_stage=1
P.AI_keys={}
P.AI_delay=min(int(P.gameEnv.drop*.8),data.delta*rnd()*4)
P.AI_delay0=data.delta
@@ -1462,6 +1461,8 @@ function Player.loadAI(P,data)--Load AI params
else
P:setRS("TRS")
end
P.AI_thread=coroutine.create(AIFUNC[data.type])
coroutine.resume(P.AI_thread,P,P.AI_keys)
end
--------------------------</Methods>--------------------------

View File

@@ -145,8 +145,8 @@ function update.alive(P,dt)
local C=P.AI_keys
P.AI_delay=P.AI_delay-1
if not C[1]then
if P.AI_stage then
P.AI_stage=AIFUNC[P.AI_mode][P.AI_stage](P,C)
if coroutine.status(P.AI_thread)=="suspended"then
coroutine.resume(P.AI_thread)
end
elseif P.AI_delay<=0 then
P:pressKey(C[1])P:releaseKey(C[1])