add new generator: bagP1inf (#916)
This commit is contained in:
@@ -476,7 +476,7 @@ do-- Mod data
|
|||||||
},
|
},
|
||||||
{no=19,id="CS",name="customSeq",
|
{no=19,id="CS",name="customSeq",
|
||||||
key="b",x=680,y=470,color='lB',
|
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,
|
func=function(P,O) P.gameEnv.sequence=O end,
|
||||||
unranked=true,
|
unranked=true,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -91,6 +91,10 @@ local seqGenBanner=setmetatable({
|
|||||||
fixed=GC.DO{100,10,
|
fixed=GC.DO{100,10,
|
||||||
{'fRect',40,4,20,2},
|
{'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)
|
},{__index=function(self,k)
|
||||||
self[k]=self.none
|
self[k]=self.none
|
||||||
return self.none
|
return self.none
|
||||||
|
|||||||
@@ -269,6 +269,83 @@ local seqGenerators={
|
|||||||
yield()
|
yield()
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
bagP1inf=function(P,seq0)
|
||||||
|
local rndGen=P.seqRND
|
||||||
|
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
|
||||||
|
while #P.nextQueue<10 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
|
||||||
|
P:getNext(seq0[i])
|
||||||
|
dist.update(i)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
yield()
|
||||||
|
end
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
return function(P)-- Return a piece-generating function for player P
|
return function(P)-- Return a piece-generating function for player P
|
||||||
local s=P.gameEnv.sequence
|
local s=P.gameEnv.sequence
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ scene.widgetList={
|
|||||||
WIDGET.newText{name='subTitle',x=530,y=50,lim=170,font=35,align='L',color='H'},
|
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',
|
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')
|
disp=CUSval('sequence'),code=CUSsto('sequence')
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user