Merge branch 'main' into imple/revise-seq-generator

This commit is contained in:
Imple Lee
2023-07-13 14:15:51 +08:00
4 changed files with 80 additions and 3 deletions

View File

@@ -476,7 +476,7 @@ do-- Mod data
},
{no=19,id="CS",name="customSeq",
key="b",x=680,y=470,color='lB',
list={'bag','bagES','his','hisPool','c2','rnd','mess','reverb'},
list={'bag','bagES','his','hisPool','c2','rnd','mess','reverb','bagP1inf'},
func=function(P,O) P.gameEnv.sequence=O end,
unranked=true,
},

View File

@@ -91,6 +91,10 @@ local seqGenBanner=setmetatable({
fixed=GC.DO{100,10,
{'fRect',40,4,20,2},
},
--TODO: add new banner for bagP1inf
bagP1inf=GC.DO{100,10,
{'fRect',40,4,20,2},
},
},{__index=function(self,k)
self[k]=self.none
return self.none

View File

@@ -2,7 +2,7 @@ local ins,rem=table.insert,table.remove
local yield=coroutine.yield
local seqGenerators={
none=function() while true do yield() end end,
none=function() end,
bag=function(rndGen,seq0)
local len=#seq0
local bag={}
@@ -222,6 +222,79 @@ local seqGenerators={
yield(seq0[i])
end
end,
bagP1inf=function(rndGen,seq0)
local len=#seq0
local function new()
local res={}
local higher=nil
local higher_dist={}
for i=1,len do
higher_dist[i]=1
end
local remaining=len+1
local unknown={}
local extra=-1
local function init()
for i=1,len do
unknown[i]=1
end
remaining=len+1
extra=-1
end
init()
function res.next_dist()
if extra>=0 then
return remaining,unknown
end
local temp={}
local temp_sum=0
for i=1,len do
local item=higher_dist[i]*(2-unknown[i])
temp[i]=item
temp_sum=temp_sum+item
end
local sum=0
for i=1,len do
temp[i]=temp[i]+temp_sum*unknown[i]
sum=sum+temp[i]
end
return sum,temp
end
function res.update(i)
if unknown[i]==0 then
assert(extra<0,"extra should be -1")
extra=i
else
unknown[i]=0
end
remaining=remaining-1
if remaining>0 then
return
end
if higher==nil then
higher=new()
end
higher.update(extra)
local _
_,higher_dist=higher.next_dist()
init()
end
return res
end
local dist=new()
while true do
local sum,mydist=dist.next_dist()
local r=rndGen:random(sum)
for i=1,len do
r=r-mydist[i]
if r<=0 then
yield(seq0[i])
dist.update(i)
break
end
end
end
end,
}
return function(s)-- Return a piece-generating function for player P
if type(s)=='function' then

View File

@@ -174,7 +174,7 @@ scene.widgetList={
WIDGET.newText{name='subTitle',x=530,y=50,lim=170,font=35,align='L',color='H'},
WIDGET.newSelector{name='sequence',x=1080,y=60,w=200,color='Y',
list={'bag','bagES','his','hisPool','c2','rnd','mess','reverb','loop','fixed'},
list={'bag','bagES','his','hisPool','c2','rnd','mess','reverb','loop','fixed','bagP1inf'},
disp=CUSval('sequence'),code=CUSsto('sequence')
},