修改/添加bot的api
更新ccBot相关代码(需要修正)
This commit is contained in:
@@ -6,6 +6,24 @@
|
|||||||
local ins,rem=table.insert,table.remove
|
local ins,rem=table.insert,table.remove
|
||||||
local yield=coroutine.yield
|
local yield=coroutine.yield
|
||||||
local bot_cc={}
|
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)
|
function bot_cc:pushNewNext(id)
|
||||||
self.bot:addNext(rem(self.nexts,1))
|
self.bot:addNext(rem(self.nexts,1))
|
||||||
ins(self.nexts,id)
|
ins(self.nexts,id)
|
||||||
@@ -32,13 +50,13 @@ function bot_cc:thread()
|
|||||||
dest[7],dest[8]=dest[2][1],dest[2][2]
|
dest[7],dest[8]=dest[2][1],dest[2][2]
|
||||||
dest[1],dest[2]=dest[3][1],dest[3][2]
|
dest[1],dest[2]=dest[3][1],dest[3][2]
|
||||||
dest[3],dest[4]=dest[4][1],dest[4][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
|
if hold then keys[1]=8 end--Hold
|
||||||
while move[1]do
|
while move[1]do
|
||||||
local m=rem(move,1)
|
local m=rem(move,1)
|
||||||
if m<4 then
|
if m<4 then
|
||||||
ins(keys,m+1)
|
ins(keys,m+1)
|
||||||
elseif not P.AIdata._20G then
|
elseif not self._20G then
|
||||||
ins(keys,13)
|
ins(keys,13)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ local ins,rem=table.insert,table.remove
|
|||||||
local baseBot={
|
local baseBot={
|
||||||
pushNewNext=NULL,
|
pushNewNext=NULL,
|
||||||
updateField=NULL,
|
updateField=NULL,
|
||||||
lockWrongPlace=NULL,
|
updateB2B=NULL,
|
||||||
|
updateCombo=NULL,
|
||||||
|
checkDest=NULL,
|
||||||
switch20G=NULL,
|
switch20G=NULL,
|
||||||
revive=NULL,
|
revive=NULL,
|
||||||
}
|
}
|
||||||
@@ -44,7 +46,7 @@ function BOT.template(arg)
|
|||||||
next=arg.next,
|
next=arg.next,
|
||||||
hold=arg.hold,
|
hold=arg.hold,
|
||||||
delay=AISpeed[arg.speedLV],
|
delay=AISpeed[arg.speedLV],
|
||||||
["args.node"]=arg.node,
|
node=arg.node,
|
||||||
}
|
}
|
||||||
elseif arg.type=='9S'then
|
elseif arg.type=='9S'then
|
||||||
return{
|
return{
|
||||||
@@ -58,41 +60,41 @@ end
|
|||||||
function BOT.new(P,data)
|
function BOT.new(P,data)
|
||||||
local bot={P=P,data=data}
|
local bot={P=P,data=data}
|
||||||
if data.type=="CC"then
|
if data.type=="CC"then
|
||||||
-- P:setRS('SRS')
|
P:setRS('SRS')
|
||||||
-- bot.keys={}
|
bot.keys={}
|
||||||
-- bot.nexts={}
|
bot.nexts={}
|
||||||
-- bot.delay=data.delay
|
bot.delay=data.delay
|
||||||
-- bot.delay0=data.delay
|
bot.delay0=data.delay
|
||||||
-- if P.gameEnv.holdCount and P.gameEnv.holdCount>1 then P:setHold(1)end
|
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 cc=require"parts.bot.cc_wrapper"
|
||||||
-- local opt,wei=cc.getConf()
|
local opt,wei=cc.getConf()
|
||||||
-- wei:fastWeights()
|
wei:fastWeights()
|
||||||
-- opt:setHold(P.AIdata.hold)
|
opt:setHold(P.AIdata.hold)
|
||||||
-- opt:set20G(P.AIdata._20G)
|
opt:set20G(P.AIdata._20G)
|
||||||
-- opt:setBag(P.AIdata.bag=='bag')
|
opt:setBag(P.AIdata.bag=='bag')
|
||||||
-- opt:setNode(P.AIdata.node)
|
opt:setNode(P.AIdata.node)
|
||||||
-- bot.ccBot=cc.new(opt,wei)
|
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})
|
|
||||||
|
|
||||||
-- for i,B in next,P.gameEnv.nextQueue do
|
local cc_lua=require"parts.bot.bot_cc"
|
||||||
-- if i<=data.next then
|
setmetatable(bot,{__index=function(self,k)
|
||||||
-- bot:addNext(B.id)
|
return
|
||||||
-- else
|
self.ccBot[k]and function(_,...)self.ccBot[k](self.ccBot,...)end or
|
||||||
-- ins(bot.nexts,B.id)
|
cc_lua[k]and function(_,...)cc_lua[k](self,...)end or
|
||||||
-- end
|
baseBot[k]or
|
||||||
-- end
|
error("No action called "..k)
|
||||||
-- bot.runningThread=coroutine.wrap(cc_lua.thread)
|
end})
|
||||||
-- bot.runningThread(bot)
|
|
||||||
|
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)
|
setmetatable(bot,botMeta)
|
||||||
elseif data.type=="9S"or true then--9s or else
|
elseif data.type=="9S"or true then--9s or else
|
||||||
TABLE.cover(baseBot,bot)
|
TABLE.cover(baseBot,bot)
|
||||||
|
|||||||
@@ -801,8 +801,8 @@ function draw.norm(P,repMode)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--Draw AI's drop destination
|
--Draw AI's drop destination
|
||||||
if P.AI_dest then
|
if P.destFX then
|
||||||
local L=P.AI_dest
|
local L=P.destFX
|
||||||
local texture=TEXTURE.puzzleMark[21]
|
local texture=TEXTURE.puzzleMark[21]
|
||||||
for i=1,#L,2 do
|
for i=1,#L,2 do
|
||||||
gc_draw(texture,30*L[i],-30*L[i+1]-30)
|
gc_draw(texture,30*L[i],-30*L[i+1]-30)
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ local function _newEmptyPlayer(id,mini)
|
|||||||
P.keyPressing={}for i=1,12 do P.keyPressing[i]=false end
|
P.keyPressing={}for i=1,12 do P.keyPressing[i]=false end
|
||||||
P.clearingRow,P.clearedRow={},{}--Clearing animation height,cleared row mark
|
P.clearingRow,P.clearedRow={},{}--Clearing animation height,cleared row mark
|
||||||
P.dropFX,P.moveFX,P.lockFX,P.clearFX={},{},{},{}
|
P.dropFX,P.moveFX,P.lockFX,P.clearFX={},{},{},{}
|
||||||
|
-- P.destFX={}--Normally created by bot
|
||||||
P.tasks={}
|
P.tasks={}
|
||||||
P.bonus={}--Texts
|
P.bonus={}--Texts
|
||||||
|
|
||||||
|
|||||||
@@ -573,21 +573,6 @@ function Player:freshBlock(mode)--string mode: push/move/fresh/newBlock
|
|||||||
end
|
end
|
||||||
end
|
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()
|
function Player:lock()
|
||||||
local CB=self.cur.bk
|
local CB=self.cur.bk
|
||||||
for i=1,#CB do
|
for i=1,#CB do
|
||||||
@@ -888,9 +873,7 @@ function Player:getBlock(id,name,color)--Get a block object
|
|||||||
end
|
end
|
||||||
function Player:getNext(id)--Push a block to nextQueue
|
function Player:getNext(id)--Push a block to nextQueue
|
||||||
ins(self.nextQueue,self:getBlock(id))
|
ins(self.nextQueue,self:getBlock(id))
|
||||||
if self.bot then
|
if self.bot then self.bot:pushNewNext(id)end
|
||||||
self.bot:pushNewNext(id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
function Player:popNext(ifhold)--Pop nextQueue to hand
|
function Player:popNext(ifhold)--Pop nextQueue to hand
|
||||||
local ENV=self.gameEnv
|
local ENV=self.gameEnv
|
||||||
@@ -1126,9 +1109,6 @@ do--Player.drop(self)--Place piece
|
|||||||
dospin=dospin+2
|
dospin=dospin+2
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.bot then
|
|
||||||
self:checkDest()
|
|
||||||
end
|
|
||||||
self:lock()
|
self:lock()
|
||||||
|
|
||||||
--Clear list of cleared-rows
|
--Clear list of cleared-rows
|
||||||
@@ -1492,6 +1472,13 @@ do--Player.drop(self)--Place piece
|
|||||||
end
|
end
|
||||||
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
|
--Check height limit
|
||||||
if cc==0 and #self.field>ENV.heightLimit then self:lose()end
|
if cc==0 and #self.field>ENV.heightLimit then self:lose()end
|
||||||
|
|
||||||
@@ -1665,9 +1652,7 @@ function Player:revive()
|
|||||||
self.field[_],self.visTime[_]=nil
|
self.field[_],self.visTime[_]=nil
|
||||||
end
|
end
|
||||||
self.garbageBeneath=0
|
self.garbageBeneath=0
|
||||||
if self.bot then
|
if self.bot then self.bot:revive()end
|
||||||
self.bot:revive()
|
|
||||||
end
|
|
||||||
|
|
||||||
self:clearAttackBuffer()
|
self:clearAttackBuffer()
|
||||||
|
|
||||||
|
|||||||
@@ -347,7 +347,7 @@ function update.alive(P,dt)
|
|||||||
end
|
end
|
||||||
P:drop(true)
|
P:drop(true)
|
||||||
if P.bot then
|
if P.bot then
|
||||||
P.bot:unexpectedLock()
|
P.bot:lockWrongPlace()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user