玩家的随机数生成器独立为四个,尝试避免联网对战时不同步错误,整理代码

This commit is contained in:
MrZ626
2021-05-13 02:34:32 +08:00
parent adbb888fe4
commit cc1261c285
25 changed files with 82 additions and 77 deletions

View File

@@ -5,6 +5,7 @@ local yield=YIELD
local seqGenerators={
none=function()while true do yield()end end,
bag=function(P,seq0)
local rndGen=P.seqRND
local len=#seq0
local bag={}
while true do
@@ -14,12 +15,13 @@ local seqGenerators={
bag[i]=seq0[len-i+1]
end
end
P:getNext(rem(bag,P:RND(#bag)))
P:getNext(rem(bag,rndGen:random(#bag)))
end
yield()
end
end,
his=function(P,seq0)
local rndGen=P.seqRND
local len=#seq0
local hisLen=ceil(len*.5)
local history=TABLE.new(0,hisLen)
@@ -27,7 +29,7 @@ local seqGenerators={
while #P.nextQueue<6 do
local r
for _=1,hisLen do--Reroll up to [hisLen] times
r=P:RND(len)
r=rndGen:random(len)
for i=1,hisLen do
if r==history[i]then
goto CONTINUE_rollAgain
@@ -43,6 +45,7 @@ local seqGenerators={
end
end,
hisPool=function(P,seq0)
local rndGen=P.seqRND
local len=#seq0
local hisLen=ceil(len*.5)
local history=TABLE.new(0,hisLen)--Indexes of mino-index
@@ -51,7 +54,7 @@ local seqGenerators={
local droughtTimes=TABLE.new(len,len)--Drought times of seq0
local pool={}for i=1,len do for _=1,5 do ins(pool,i)end end--5 times indexes of seq0
local function poolPick()
local r=P:RND(poolLen)
local r=rndGen:random(poolLen)
local res=pool[r]
--Find droughtest(s) minoes
@@ -72,7 +75,7 @@ local seqGenerators={
--Update pool
-- print("Rem "..res)
pool[r]=droughtList[P:RND(#droughtList)]
pool[r]=droughtList[rndGen:random(#droughtList)]
-- print("Add "..pool[r])
return res
@@ -105,6 +108,7 @@ local seqGenerators={
end
end,
c2=function(P,seq0)
local rndGen=P.seqRND
local len=#seq0
local weight={}
for i=1,len do weight[i]=0 end
@@ -113,7 +117,7 @@ local seqGenerators={
while #P.nextQueue<6 do
local maxK=1
for i=1,len do
weight[i]=weight[i]*.5+P:RND()
weight[i]=weight[i]*.5+rndGen:random()
if weight[i]>weight[maxK]then
maxK=i
end
@@ -127,13 +131,14 @@ local seqGenerators={
rnd=function(P,seq0)
if #seq0==1 then
local i=seq0[1]
while true do P:getNext(i) yield() end
while true do P:getNext(i)yield()end
else
local rndGen=P.seqRND
local len=#seq0
local last=0
while true do
while #P.nextQueue<6 do
local r=P:RND(len-1)
local r=rndGen:random(len-1)
if r>=last then r=r+1 end
P:getNext(seq0[r])
last=r
@@ -143,32 +148,34 @@ local seqGenerators={
end
end,
mess=function(P,seq0)
local rndGen=P.seqRND
while true do
while #P.nextQueue<6 do
P:getNext(seq0[P:RND(#seq0)])
P:getNext(seq0[rndGen:random(#seq0)])
end
yield()
end
end,
reverb=function(P,seq0)
local rndGen=P.seqRND
local bufferSeq,bag={},{}
while true do
while #P.nextQueue<6 do
if #bag==0 then
for i=1,#seq0 do bufferSeq[i]=seq0[i]end
repeat
local r=rem(bufferSeq,P:RND(#bag))
local r=rem(bufferSeq,rndGen:random(#bag))
local p=1
repeat
ins(bag,r)
p=p-.15-P:RND()
p=p-.15-rndGen:random()
until p<0
until #bufferSeq==0
for i=1,#bag do
bufferSeq[i]=bag[i]
end
end
P:getNext(rem(bag,P:RND(#bag)))
P:getNext(rem(bag,rndGen:random(#bag)))
end
yield()
end