@@ -6,26 +6,25 @@
|
|||||||
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()
|
function bot_cc:checkDest()
|
||||||
local dest=self.destFX
|
local dest=self.P.destFX
|
||||||
if not dest then return end
|
if not dest then return end
|
||||||
local CB=self.cur.bk
|
local CB=self.P.cur.bk
|
||||||
for k=1,#dest,2 do
|
for k=1,#dest,2 do
|
||||||
local r=CB[dest[k+1]-self.curY+2]
|
local r=CB[dest[k+1]-self.P.curY+2]
|
||||||
if not r or not r[dest[k]-self.curX+2]then
|
if not r or not r[dest[k]-self.P.curX+2]then
|
||||||
if self.bot then
|
self:lockWrongPlace()
|
||||||
self.bot:lockWrongPlace()
|
self.P.destFX=nil
|
||||||
end
|
|
||||||
self.destFX=nil
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
function bot_cc:revive()
|
||||||
|
TABLE.cut(self.P.holdQueue)
|
||||||
|
self.P:loadAI(self.data)
|
||||||
|
end
|
||||||
function bot_cc:pushNewNext(id)
|
function bot_cc:pushNewNext(id)
|
||||||
self.bot:addNext(rem(self.nexts,1))
|
self.ccBot:addNext(rem(self.nexts,1))
|
||||||
ins(self.nexts,id)
|
ins(self.nexts,id)
|
||||||
end
|
end
|
||||||
function bot_cc:thread()
|
function bot_cc:thread()
|
||||||
@@ -40,7 +39,7 @@ function bot_cc:thread()
|
|||||||
local success,result,dest,hold,move
|
local success,result,dest,hold,move
|
||||||
repeat
|
repeat
|
||||||
yield()
|
yield()
|
||||||
success,result,dest,hold,move=ccBot:getMove()
|
success,result,dest,hold,move=pcall(ccBot.getMove,ccBot)
|
||||||
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
|
||||||
@@ -56,7 +55,7 @@ function bot_cc:thread()
|
|||||||
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 self._20G then
|
elseif not self.data._20G then
|
||||||
ins(keys,13)
|
ins(keys,13)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -70,4 +69,25 @@ function bot_cc:thread()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
function bot_cc:updateField()
|
||||||
|
local P=self.P
|
||||||
|
local F,i={},1
|
||||||
|
for y=1,#P.field do
|
||||||
|
for x=1,10 do
|
||||||
|
F[i],i=P.field[y][x]>0,i+1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
while i<=400 do
|
||||||
|
F[i],i=false,i+1
|
||||||
|
end
|
||||||
|
if not pcall(self.ccBot.reset,self.ccBot,F,P.b2b>=100,P.combo)then
|
||||||
|
print("CC is dead ("..P.id..")","error")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function bot_cc:switch20G()
|
||||||
|
TABLE.cut(self.P.holdQueue)
|
||||||
|
self.data._20G=true
|
||||||
|
self.P:loadAI(self.data)
|
||||||
|
end
|
||||||
|
bot_cc.lockWrongPlace=bot_cc.updateField
|
||||||
return bot_cc
|
return bot_cc
|
||||||
@@ -38,15 +38,28 @@ local botMeta={__index=_undefMethod}
|
|||||||
local BOT={}
|
local BOT={}
|
||||||
|
|
||||||
local AISpeed={60,50,40,30,20,14,10,6,4,3}
|
local AISpeed={60,50,40,30,20,14,10,6,4,3}
|
||||||
|
-- For CC bot:
|
||||||
|
-- TODO you still need to switch20G() at the right time.
|
||||||
|
-- since it's not cc-specific I'm not dealing with it for now
|
||||||
|
--[[
|
||||||
|
next: number of nexts
|
||||||
|
hold: holdable?
|
||||||
|
speedLV: level
|
||||||
|
node: search nodes
|
||||||
|
randomizer: random generator
|
||||||
|
_20G: 20G?
|
||||||
|
]]
|
||||||
function BOT.template(arg)
|
function BOT.template(arg)
|
||||||
if arg.type=='CC'then
|
if arg.type=='CC'then
|
||||||
if not arg.hold then arg.hold=false else arg.hold=true end
|
if not arg.randomizer then arg.randomizer='bag' end
|
||||||
return{
|
return{
|
||||||
type='CC',
|
type='CC',
|
||||||
next=arg.next,
|
next=arg.next,
|
||||||
hold=arg.hold,
|
hold=arg.hold,
|
||||||
delay=AISpeed[arg.speedLV],
|
delay=AISpeed[arg.speedLV],
|
||||||
node=arg.node,
|
node=arg.node,
|
||||||
|
bag=arg.randomizer=='bag',
|
||||||
|
_20G=arg._20G,
|
||||||
}
|
}
|
||||||
elseif arg.type=='9S'then
|
elseif arg.type=='9S'then
|
||||||
return{
|
return{
|
||||||
@@ -65,28 +78,26 @@ function BOT.new(P,data)
|
|||||||
bot.nexts={}
|
bot.nexts={}
|
||||||
bot.delay=data.delay
|
bot.delay=data.delay
|
||||||
bot.delay0=data.delay
|
bot.delay0=data.delay
|
||||||
bot._20G=P._20G
|
|
||||||
if P.gameEnv.holdCount and P.gameEnv.holdCount>1 then P:setHold(1)end
|
if P.gameEnv.holdCount and P.gameEnv.holdCount>1 then P:setHold(1)end
|
||||||
|
|
||||||
local cc=require"parts.bot.cc_wrapper"
|
local cc=require"CCloader"
|
||||||
local opt,wei=cc.getConf()
|
local opt,wei=cc.getDefaultConfig()
|
||||||
wei:fastWeights()
|
wei:fastWeights()
|
||||||
opt:setHold(P.AIdata.hold)
|
opt:setHold(data.hold)
|
||||||
opt:set20G(P.AIdata._20G)
|
opt:set20G(data._20G)
|
||||||
opt:setBag(P.AIdata.bag=='bag')
|
opt:setBag(data.bag=='bag')
|
||||||
opt:setNode(P.AIdata.node)
|
opt:setNode(data.node)
|
||||||
bot.ccBot=cc.new(opt,wei)
|
bot.ccBot=cc.launchAsync(opt,wei)
|
||||||
|
|
||||||
local cc_lua=require"parts.bot.bot_cc"
|
local cc_lua=require"parts.bot.bot_cc"
|
||||||
setmetatable(bot,{__index=function(self,k)
|
setmetatable(bot,{__index=function(self,k)
|
||||||
return
|
return
|
||||||
self.ccBot[k]and function(_,...)self.ccBot[k](self.ccBot,...)end or
|
self.ccBot[k] and function(_,...)self.ccBot[k](self.ccBot,...)end or
|
||||||
cc_lua[k]and function(_,...)cc_lua[k](self,...)end or
|
cc_lua[k] and function(_,...)cc_lua[k](self,...)end or
|
||||||
baseBot[k]or
|
baseBot[k] and baseBot[k] or
|
||||||
error("No action called "..k)
|
error("MrZ did something bad again! He just wanted "..k)
|
||||||
end})
|
end})
|
||||||
|
|
||||||
for i,B in next,P.gameEnv.nextQueue do
|
for i,B in next,P.nextQueue do
|
||||||
if i<=data.next then
|
if i<=data.next then
|
||||||
bot:addNext(B.id)
|
bot:addNext(B.id)
|
||||||
else
|
else
|
||||||
@@ -95,7 +106,6 @@ function BOT.new(P,data)
|
|||||||
end
|
end
|
||||||
bot.runningThread=coroutine.wrap(cc_lua.thread)
|
bot.runningThread=coroutine.wrap(cc_lua.thread)
|
||||||
bot.runningThread(bot)
|
bot.runningThread(bot)
|
||||||
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)
|
||||||
TABLE.cover(require"parts.bot.bot_9s",bot)
|
TABLE.cover(require"parts.bot.bot_9s",bot)
|
||||||
|
|||||||
Reference in New Issue
Block a user