Skip to content

Commit

Permalink
add new generator: bagP1inf (#916)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImpleLee authored Jul 13, 2023
1 parent b3a8724 commit 3dc6168
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
2 changes: 1 addition & 1 deletion parts/gameTables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
4 changes: 4 additions & 0 deletions parts/player/draw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
77 changes: 77 additions & 0 deletions parts/player/seqGenerators.lua
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,83 @@ local seqGenerators={
yield()
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
local s=P.gameEnv.sequence
Expand Down
2 changes: 1 addition & 1 deletion parts/scenes/custom_sequence.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
},

Expand Down

0 comments on commit 3dc6168

Please sign in to comment.