重构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
BGM

View File

@@ -33,7 +33,7 @@ return{
}
PLY.newPlayer(1,340,15)
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
local r=rnd(2,49)
if L[r]then L[r],t=false,t-1 end

View File

@@ -33,7 +33,7 @@ return{
}
PLY.newPlayer(1,340,15)
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
local r=rnd(2,49)
if L[r]then L[r],t=false,t-1 end

View File

@@ -33,7 +33,7 @@ return{
}
PLY.newPlayer(1,340,15)
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
local r=rnd(2,49)
if L[r]then L[r],t=false,t-1 end

View File

@@ -33,7 +33,7 @@ return{
}
PLY.newPlayer(1,340,15)
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
local r=rnd(2,99)
if L[r]then L[r],t=false,t-1 end

View File

@@ -33,7 +33,7 @@ return{
}
PLY.newPlayer(1,340,15)
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
local r=rnd(2,99)
if L[r]then L[r],t=false,t-1 end

View File

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

View File

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

View File

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