重构CC加载代码

This commit is contained in:
MrZ626
2020-09-10 18:29:12 +08:00
parent c2519a32e1
commit f6deb34121
10 changed files with 74 additions and 69 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,3 @@
lib libAndroid
font.ttf font.ttf
BGM BGM

View File

@@ -33,7 +33,7 @@ return{
} }
PLY.newPlayer(1,340,15) PLY.newPlayer(1,340,15)
local L={}for i=1,49 do L[i]=true end local L={}for i=1,49 do L[i]=true end
local t=CCloader_filename[system] and 2 or 0 local t=CC and 2 or 0
while t>0 do while t>0 do
local r=rnd(2,49) local r=rnd(2,49)
if L[r]then L[r],t=false,t-1 end if L[r]then L[r],t=false,t-1 end

View File

@@ -33,7 +33,7 @@ return{
} }
PLY.newPlayer(1,340,15) PLY.newPlayer(1,340,15)
local L={}for i=1,49 do L[i]=true end local L={}for i=1,49 do L[i]=true end
local t=CCloader_filename[system] and 4 or 0 local t=CC and 4 or 0
while t>0 do while t>0 do
local r=rnd(2,49) local r=rnd(2,49)
if L[r]then L[r],t=false,t-1 end if L[r]then L[r],t=false,t-1 end

View File

@@ -33,7 +33,7 @@ return{
} }
PLY.newPlayer(1,340,15) PLY.newPlayer(1,340,15)
local L={}for i=1,49 do L[i]=true end local L={}for i=1,49 do L[i]=true end
local t=CCloader_filename[system] and 6 or 0 local t=CC and 6 or 0
while t>0 do while t>0 do
local r=rnd(2,49) local r=rnd(2,49)
if L[r]then L[r],t=false,t-1 end if L[r]then L[r],t=false,t-1 end

View File

@@ -33,7 +33,7 @@ return{
} }
PLY.newPlayer(1,340,15) PLY.newPlayer(1,340,15)
local L={}for i=1,100 do L[i]=true end local L={}for i=1,100 do L[i]=true end
local t=CCloader_filename[system] and 4 or 0 local t=CC and 4 or 0
while t>0 do while t>0 do
local r=rnd(2,99) local r=rnd(2,99)
if L[r]then L[r],t=false,t-1 end if L[r]then L[r],t=false,t-1 end

View File

@@ -33,7 +33,7 @@ return{
} }
PLY.newPlayer(1,340,15) PLY.newPlayer(1,340,15)
local L={}for i=1,100 do L[i]=true end local L={}for i=1,100 do L[i]=true end
local t=CCloader_filename[system] and 4 or 0 local t=CC and 4 or 0
while t>0 do while t>0 do
local r=rnd(2,99) local r=rnd(2,99)
if L[r]then L[r],t=false,t-1 end if L[r]then L[r],t=false,t-1 end

View File

@@ -33,7 +33,7 @@ return{
} }
PLY.newPlayer(1,340,15) PLY.newPlayer(1,340,15)
local L={}for i=1,100 do L[i]=true end local L={}for i=1,100 do L[i]=true end
local t=CCloader_filename[system] and 4 or 0 local t=CC and 4 or 0
while t>0 do while t>0 do
local r=rnd(2,99) local r=rnd(2,99)
if L[r]then L[r],t=false,t-1 end if L[r]then L[r],t=false,t-1 end

View File

@@ -16,46 +16,51 @@ local Timer=love.timer.getTime
local blockPos={4,4,4,4,4,5,4} local blockPos={4,4,4,4,4,5,4}
local scs={{0,1},{0,1},{0,1},{0,1},{0,1},{.5,.5},{-.5,1.5}} local scs={{0,1},{0,1},{0,1},{0,1},{0,1},{.5,.5},{-.5,1.5}}
-------------------------------------------------Cold clear -------------------------------------------------Cold clear
local function loadCC() do
local SYS=({ if system=="Windows"then
Windows={"CCloader.dll",{"x86_64","x86"}}, local success,message=require("CCloader")
Android={"libCCloader.so",{"arm64-v8a","armeabi-v7a"}}, if success then
Linux={"libCCloader.so",{"x86_64"}}, LOG.print("CC load successfully","warn",color.green)
})[system] else
if not SYS then return end LOG.print("Cannot load CC: "..message,"warn",color.red)
end
local fs=love.filesystem elseif system=="Android"then
local libFunc,success,message local armList={"arm64-v8a","armeabi-v7a"}
for i=1,#SYS[2]do local fs=love.filesystem
local CCloader_f,size=fs.read("data",table.concat({"lib",system,SYS[2][i],SYS[1]},"/")) local libFunc,success,message
if CCloader_f then for i=1,#armList do
LOG.print("Read CC-"..SYS[2][i].." successfully","warn",color.green) local CCloader_f,size=fs.read("data","libAndroid/"..armList[i].."/libCCloader.so")
success,message=fs.write(SYS[1],CCloader_f,size) if CCloader_f then
if success then LOG.print("Read CC-"..armList[i].." successfully","warn",color.green)
LOG.print("Write CC-"..SYS[2][i].." to saving successfully","warn",color.green) success,message=fs.write("libCCloader.so",CCloader_f,size)
libFunc,message=package.loadlib(table.concat({fs.getSaveDirectory(),SYS[1]},"/"),"luaopen_CCloader") if success then
if libFunc then LOG.print("Write CC-"..armList[i].." to saving successfully","warn",color.green)
LOG.print("CC lib loaded","warn",color.green) libFunc,message=package.loadlib(table.concat({fs.getSaveDirectory(),"libCCloader.so"},"/"),"luaopen_CCloader")
break if libFunc then
LOG.print("CC lib loaded","warn",color.green)
break
else
LOG.print("Cannot load CC: "..message,"warn",color.red)
end
else else
LOG.print("Cannot load CC: "..message,"warn",color.red) LOG.print("Write CC-"..armList[i].." to saving failed","warn",color.red)
end end
else else
LOG.print("Write CC-"..SYS[2][i].." to saving failed","warn",color.red) LOG.print("Read CC-"..armList[i].." failed","warn",color.red)
end end
else
LOG.print("Read CC-"..SYS[2][i].." failed","warn",color.red)
end end
if not libFunc then
LOG.print("failed to load CC","warn",color.red)
goto FAILED
end
LOG.print("CC load successfully","warn",color.green)
libFunc()
else
LOG.print("No CC for "..system,"warn",color.red)
goto FAILED
end end
if not libFunc then
SYS=nil
LOG.print("failed to load CC","warn",color.red)
return
end
LOG.print("CC load successfully","warn",color.green)
libFunc()
local CCblockID={6,5,4,3,2,1,0} local CCblockID={6,5,4,3,2,1,0}
BOT={ CC={
getConf= cc.get_default_config ,--()options,weights getConf= cc.get_default_config ,--()options,weights
--setConf= cc.set_options ,--(options,hold,20g,bag7) --setConf= cc.set_options ,--(options,hold,20g,bag7)
@@ -83,21 +88,21 @@ local function loadCC()
while i<400 do while i<400 do
F[i],i=false,i+1 F[i],i=false,i+1
end end
BOT.update(P.AI_bot,F,P.b2b>=100,P.combo) CC.update(P.AI_bot,F,P.b2b>=100,P.combo)
end end
function CC_switch20G(P) function CC_switch20G(P)
P.AIdata._20G=true P.AIdata._20G=true
P.AI_keys={} P.AI_keys={}
BOT.destroy(P.AI_bot) CC.destroy(P.AI_bot)
local opt,wei=BOT.getConf() local opt,wei=CC.getConf()
BOT.setHold(opt,P.AIdata.hold) CC.setHold(opt,P.AIdata.hold)
BOT.set20G(opt,P.AIdata._20G) CC.set20G(opt,P.AIdata._20G)
BOT.setBag(opt,P.AIdata.bag7) CC.setBag(opt,P.AIdata.bag7)
BOT.setNode(opt,P.AIdata.node) CC.setNode(opt,P.AIdata.node)
P.AI_bot=BOT.new(opt,wei) P.AI_bot=CC.new(opt,wei)
BOT.free(opt)BOT.free(wei) CC.free(opt)CC.free(wei)
for i=1,P.AIdata.next do for i=1,P.AIdata.next do
BOT.addNext(P.AI_bot,CCblockID[P.next[i].id]) CC.addNext(P.AI_bot,CCblockID[P.next[i].id])
end end
CC_updateField(P) CC_updateField(P)
P.hd=nil P.hd=nil
@@ -110,12 +115,12 @@ local function loadCC()
P:newNext() P:newNext()
local id=CCblockID[P.next[P.AIdata.next].id] local id=CCblockID[P.next[P.AIdata.next].id]
if id then if id then
BOT.addNext(P.AI_bot,id) CC.addNext(P.AI_bot,id)
end end
collectgarbage() collectgarbage()
end end
end end
loadCC() ::FAILED::
-------------------------------------------------9 Stack setup -------------------------------------------------9 Stack setup
local dirCount={1,1,3,3,3,0,1} local dirCount={1,1,3,3,3,0,1}
local spinOffset={ local spinOffset={
@@ -314,11 +319,11 @@ return{
}, },
["CC"]={ ["CC"]={
function(P)--Start thinking function(P)--Start thinking
BOT.think(P.AI_bot) CC.think(P.AI_bot)
return 2 return 2
end, end,
function(P,ctrl)--Poll keys function(P,ctrl)--Poll keys
local success,dest,hold,move=BOT.getMove(P.AI_bot) local success,dest,hold,move=CC.getMove(P.AI_bot)
if success==2 then if success==2 then
ins(ctrl,6) ins(ctrl,6)
return 3 return 3

View File

@@ -34,9 +34,9 @@ function destroyPlayers()
freeRow.discard(rem(P.visTime)) freeRow.discard(rem(P.visTime))
end end
if P.AI_mode=="CC"then if P.AI_mode=="CC"then
BOT.free(P.bot_opt) CC.free(P.bot_opt)
BOT.free(P.bot_wei) CC.free(P.bot_wei)
BOT.destroy(P.AI_bot) CC.destroy(P.AI_bot)
P.AI_mode=nil P.AI_mode=nil
end end
players[i]=nil players[i]=nil

View File

@@ -1165,18 +1165,18 @@ local function loadAI(P,AIdata)--Load AI params
bag=AIdata.bag, bag=AIdata.bag,
node=AIdata.node, node=AIdata.node,
} }
if not BOT then P.AI_mode="9S"end if not CC then P.AI_mode="9S"end
if P.AI_mode=="CC"then if P.AI_mode=="CC"then
P.RS=kickList.AIRS P.RS=kickList.AIRS
local opt,wei=BOT.getConf() local opt,wei=CC.getConf()
BOT.setHold(opt,P.AIdata.hold) CC.setHold(opt,P.AIdata.hold)
BOT.set20G(opt,P.AIdata._20G) CC.set20G(opt,P.AIdata._20G)
BOT.setBag(opt,P.AIdata.bag=="bag") CC.setBag(opt,P.AIdata.bag=="bag")
BOT.setNode(opt,P.AIdata.node) CC.setNode(opt,P.AIdata.node)
P.AI_bot=BOT.new(opt,wei) P.AI_bot=CC.new(opt,wei)
BOT.free(opt)BOT.free(wei) CC.free(opt)CC.free(wei)
for i=1,AIdata.next do for i=1,AIdata.next do
BOT.addNext(P.AI_bot,CCblockID[P.next[i].id]) CC.addNext(P.AI_bot,CCblockID[P.next[i].id])
end end
elseif P.AI_mode=="9S"then elseif P.AI_mode=="9S"then
P.RS=kickList.TRS P.RS=kickList.TRS
@@ -1811,7 +1811,7 @@ function player.hold(P,ifpre)
if P.AI_mode=="CC"then if P.AI_mode=="CC"then
local next=P.next[P.AIdata.next] local next=P.next[P.AIdata.next]
if next then if next then
BOT.addNext(P.AI_bot,CCblockID[next.id]) CC.addNext(P.AI_bot,CCblockID[next.id])
end end
end end
else else
@@ -1851,7 +1851,7 @@ function player.popNext(P)--Pop next queue to hand
if P.AI_mode=="CC"then if P.AI_mode=="CC"then
local next=P.next[P.AIdata.next] local next=P.next[P.AIdata.next]
if next then if next then
BOT.addNext(P.AI_bot,CCblockID[next.id]) CC.addNext(P.AI_bot,CCblockID[next.id])
end end
end end
@@ -2493,7 +2493,7 @@ function player.lose(P)
end end
if P.AI_mode=="CC"then if P.AI_mode=="CC"then
BOT.destroy(P.AI_bot) CC.destroy(P.AI_bot)
P.hd=nil P.hd=nil
loadAI(P,P.AIdata) loadAI(P,P.AIdata)
P:popNext() P:popNext()