add new generator: bagP1inf (#916)

This commit is contained in:
Imple Lee
2023-07-13 13:26:17 +08:00
committed by GitHub
parent b3a8724538
commit 3dc61688c4
4 changed files with 83 additions and 2 deletions

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

@@ -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