修改/添加bot的api

更新ccBot相关代码(需要修正)
This commit is contained in:
MrZ626
2021-08-26 02:43:16 +08:00
parent b7d5a3f9c6
commit f77d8d5219
6 changed files with 70 additions and 64 deletions

View File

@@ -6,6 +6,24 @@
local ins,rem=table.insert,table.remove
local yield=coroutine.yield
local bot_cc={}
function bot_cc:switch20G()
self._20G=true
end
function bot_cc:checkDest()
local dest=self.destFX
if not dest then return end
local CB=self.cur.bk
for k=1,#dest,2 do
local r=CB[dest[k+1]-self.curY+2]
if not r or not r[dest[k]-self.curX+2]then
if self.bot then
self.bot:lockWrongPlace()
end
self.destFX=nil
return
end
end
end
function bot_cc:pushNewNext(id)
self.bot:addNext(rem(self.nexts,1))
ins(self.nexts,id)
@@ -32,13 +50,13 @@ function bot_cc:thread()
dest[7],dest[8]=dest[2][1],dest[2][2]
dest[1],dest[2]=dest[3][1],dest[3][2]
dest[3],dest[4]=dest[4][1],dest[4][2]
P.AI_dest=dest
P.destFX=dest
if hold then keys[1]=8 end--Hold
while move[1]do
local m=rem(move,1)
if m<4 then
ins(keys,m+1)
elseif not P.AIdata._20G then
elseif not self._20G then
ins(keys,13)
end
end

View File

@@ -3,7 +3,9 @@ local ins,rem=table.insert,table.remove
local baseBot={
pushNewNext=NULL,
updateField=NULL,
lockWrongPlace=NULL,
updateB2B=NULL,
updateCombo=NULL,
checkDest=NULL,
switch20G=NULL,
revive=NULL,
}
@@ -44,7 +46,7 @@ function BOT.template(arg)
next=arg.next,
hold=arg.hold,
delay=AISpeed[arg.speedLV],
["args.node"]=arg.node,
node=arg.node,
}
elseif arg.type=='9S'then
return{
@@ -58,41 +60,41 @@ end
function BOT.new(P,data)
local bot={P=P,data=data}
if data.type=="CC"then
-- P:setRS('SRS')
-- bot.keys={}
-- bot.nexts={}
-- bot.delay=data.delay
-- bot.delay0=data.delay
-- if P.gameEnv.holdCount and P.gameEnv.holdCount>1 then P:setHold(1)end
P:setRS('SRS')
bot.keys={}
bot.nexts={}
bot.delay=data.delay
bot.delay0=data.delay
bot._20G=P._20G
if P.gameEnv.holdCount and P.gameEnv.holdCount>1 then P:setHold(1)end
-- local cc=require"parts.bot.cc_wrapper"
-- local opt,wei=cc.getConf()
-- wei:fastWeights()
-- opt:setHold(P.AIdata.hold)
-- opt:set20G(P.AIdata._20G)
-- opt:setBag(P.AIdata.bag=='bag')
-- opt:setNode(P.AIdata.node)
-- bot.ccBot=cc.new(opt,wei)
-- local cc_lua=require"parts.bot.bot_cc"
-- setmetatable(bot,{__index=function(self,k)
-- if self.ccBot[k]then
-- self.ccBot[k](self.ccBot)
-- elseif cc_lua[k]then
-- cc_lua[k](self)
-- elseif baseBot[k]then
-- baseBot[k](self)
-- end
-- end})
local cc=require"parts.bot.cc_wrapper"
local opt,wei=cc.getConf()
wei:fastWeights()
opt:setHold(P.AIdata.hold)
opt:set20G(P.AIdata._20G)
opt:setBag(P.AIdata.bag=='bag')
opt:setNode(P.AIdata.node)
bot.ccBot=cc.new(opt,wei)
-- for i,B in next,P.gameEnv.nextQueue do
-- if i<=data.next then
-- bot:addNext(B.id)
-- else
-- ins(bot.nexts,B.id)
-- end
-- end
-- bot.runningThread=coroutine.wrap(cc_lua.thread)
-- bot.runningThread(bot)
local cc_lua=require"parts.bot.bot_cc"
setmetatable(bot,{__index=function(self,k)
return
self.ccBot[k]and function(_,...)self.ccBot[k](self.ccBot,...)end or
cc_lua[k]and function(_,...)cc_lua[k](self,...)end or
baseBot[k]or
error("No action called "..k)
end})
for i,B in next,P.gameEnv.nextQueue do
if i<=data.next then
bot:addNext(B.id)
else
ins(bot.nexts,B.id)
end
end
bot.runningThread=coroutine.wrap(cc_lua.thread)
bot.runningThread(bot)
setmetatable(bot,botMeta)
elseif data.type=="9S"or true then--9s or else
TABLE.cover(baseBot,bot)

View File

@@ -801,8 +801,8 @@ function draw.norm(P,repMode)
end
--Draw AI's drop destination
if P.AI_dest then
local L=P.AI_dest
if P.destFX then
local L=P.destFX
local texture=TEXTURE.puzzleMark[21]
for i=1,#L,2 do
gc_draw(texture,30*L[i],-30*L[i+1]-30)

View File

@@ -117,6 +117,7 @@ local function _newEmptyPlayer(id,mini)
P.keyPressing={}for i=1,12 do P.keyPressing[i]=false end
P.clearingRow,P.clearedRow={},{}--Clearing animation height,cleared row mark
P.dropFX,P.moveFX,P.lockFX,P.clearFX={},{},{},{}
-- P.destFX={}--Normally created by bot
P.tasks={}
P.bonus={}--Texts

View File

@@ -573,21 +573,6 @@ function Player:freshBlock(mode)--string mode: push/move/fresh/newBlock
end
end
end
function Player:checkDest()
if not self.AI_dest then return end
local dest=self.AI_dest
local CB=self.cur.bk
for k=1,#dest,2 do
local r=CB[dest[k+1]-self.curY+2]
if not r or not r[dest[k]-self.curX+2]then
if self.bot then
self.bot:lockWrongPlace()
end
self.AI_dest=nil
return
end
end
end
function Player:lock()
local CB=self.cur.bk
for i=1,#CB do
@@ -888,9 +873,7 @@ function Player:getBlock(id,name,color)--Get a block object
end
function Player:getNext(id)--Push a block to nextQueue
ins(self.nextQueue,self:getBlock(id))
if self.bot then
self.bot:pushNewNext(id)
end
if self.bot then self.bot:pushNewNext(id)end
end
function Player:popNext(ifhold)--Pop nextQueue to hand
local ENV=self.gameEnv
@@ -1126,9 +1109,6 @@ do--Player.drop(self)--Place piece
dospin=dospin+2
end
if self.bot then
self:checkDest()
end
self:lock()
--Clear list of cleared-rows
@@ -1492,6 +1472,13 @@ do--Player.drop(self)--Place piece
end
end
--Check bot things
if self.bot then
self.bot:checkDest()
self.bot:updateB2B(self.b2b)
self.bot:updateCombo(self.combo)
end
--Check height limit
if cc==0 and #self.field>ENV.heightLimit then self:lose()end
@@ -1665,9 +1652,7 @@ function Player:revive()
self.field[_],self.visTime[_]=nil
end
self.garbageBeneath=0
if self.bot then
self.bot:revive()
end
if self.bot then self.bot:revive()end
self:clearAttackBuffer()

View File

@@ -347,7 +347,7 @@ function update.alive(P,dt)
end
P:drop(true)
if P.bot then
P.bot:unexpectedLock()
P.bot:lockWrongPlace()
end
end
end