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

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

@@ -272,7 +272,7 @@ return{
--Check if time to change target
yield()
if P:RND()<.00126 then
if P.aiRND:random()<.00126 then
P:changeAtkMode(rnd()<.85 and 1 or #P.atker>3 and 4 or rnd()<.3 and 2 or 3)
end
end
@@ -315,7 +315,7 @@ return{
--Check if time to change target
yield()
if P:RND()<.00126 then
if P.aiRND:random()<.00126 then
P:changeAtkMode(rnd()<.85 and 1 or #P.atker>3 and 4 or rnd()<.3 and 2 or 3)
end
end

View File

@@ -12,12 +12,12 @@ return{
local D=P.modeData
if D.wave<20 then
local t=1500-30*D.wave--1500~900
table.insert(P.atkBuffer,{line=generateLine(P:RND(4,7)),amount=12,countdown=t,cd0=t,time=0,sent=false,lv=3})
table.insert(P.atkBuffer,{line=generateLine(P:RND(3,8)),amount=10,countdown=t,cd0=t,time=0,sent=false,lv=4})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(4,7)),amount=12,countdown=t,cd0=t,time=0,sent=false,lv=3})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(3,8)),amount=10,countdown=t,cd0=t,time=0,sent=false,lv=4})
else
local t=900-10*(D.wave-20)--900~600
table.insert(P.atkBuffer,{line=generateLine(P:RND(10)),amount=14,countdown=t,cd0=t,time=0,sent=false,lv=4})
table.insert(P.atkBuffer,{line=generateLine(P:RND(4,7)),amount=8,countdown=t,cd0=t,time=0,sent=false,lv=5})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(10)),amount=14,countdown=t,cd0=t,time=0,sent=false,lv=4})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(4,7)),amount=8,countdown=t,cd0=t,time=0,sent=false,lv=5})
end
P.atkBufferSum=P.atkBufferSum+22
P.stat.recv=P.stat.recv+22

View File

@@ -12,16 +12,16 @@ return{
local s
local t=800-10*D.wave--800~700~600~500
if D.wave<10 then
table.insert(P.atkBuffer,{line=generateLine(P:RND(5,6)),amount=9,countdown=t,cd0=t,time=0,sent=false,lv=3})
table.insert(P.atkBuffer,{line=generateLine(P:RND(4,7)),amount=11,countdown=t,cd0=t+62,time=0,sent=false,lv=4})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(5,6)),amount=9,countdown=t,cd0=t,time=0,sent=false,lv=3})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(4,7)),amount=11,countdown=t,cd0=t+62,time=0,sent=false,lv=4})
s=20
elseif D.wave<20 then
table.insert(P.atkBuffer,{line=generateLine(P:RND(3,8)),amount=11,countdown=t,cd0=t,time=0,sent=false,lv=4})
table.insert(P.atkBuffer,{line=generateLine(P:RND(4,7)),amount=13,countdown=t,cd0=t+62,time=0,sent=false,lv=5})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(3,8)),amount=11,countdown=t,cd0=t,time=0,sent=false,lv=4})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(4,7)),amount=13,countdown=t,cd0=t+62,time=0,sent=false,lv=5})
s=24
else
table.insert(P.atkBuffer,{line=generateLine(P:RND(2)*9-8),amount=14,countdown=t,cd0=t,time=0,sent=false,lv=5})
table.insert(P.atkBuffer,{line=generateLine(P:RND(3,8)),amount=14,countdown=t+62,cd0=t,time=0,sent=false,lv=5})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(2)*9-8),amount=14,countdown=t,cd0=t,time=0,sent=false,lv=5})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(3,8)),amount=14,countdown=t+62,cd0=t,time=0,sent=false,lv=5})
s=28
end
P.atkBufferSum=P.atkBufferSum+s

View File

@@ -5,7 +5,7 @@ return{
freshLimit=15,
dropPiece=function(P)
if P.lastPiece.atk>0 then
P:receive(nil,P.lastPiece.atk,60,generateLine(P:RND(10)))
P:receive(nil,P.lastPiece.atk,60,generateLine(P.holeRND:random(10)))
end
if P.stat.atk>=100 then
P:win('finish')

View File

@@ -5,7 +5,7 @@ return{
freshLimit=15,
dropPiece=function(P)
if P.lastPiece.atk>0 then
P:receive(nil,P.lastPiece.atk,30,generateLine(P:RND(10)))
P:receive(nil,P.lastPiece.atk,30,generateLine(P.holeRND:random(10)))
end
if P.stat.atk>=100 then
P:win('finish')

View File

@@ -4,7 +4,7 @@ return{
drop=30,lock=60,
dropPiece=function(P)
if P.lastPiece.atk>0 then
P:receive(nil,P.lastPiece.atk,120,generateLine(P:RND(10)))
P:receive(nil,P.lastPiece.atk,120,generateLine(P.holeRND:random(10)))
end
if P.stat.atk>=100 then
P:win('finish')

View File

@@ -5,7 +5,7 @@ return{
freshLimit=10,
dropPiece=function(P)
if P.lastPiece.atk>0 then
P:receive(nil,P.lastPiece.atk,0,generateLine(P:RND(10)))
P:receive(nil,P.lastPiece.atk,0,generateLine(P.holeRND:random(10)))
end
if P.stat.atk>=100 then
P:win('finish')

View File

@@ -37,18 +37,18 @@ return{
P.visTime[i]=FREEROW.get(20)
for x=4,7 do F[i][x]=0 end
end
if P:RND()<.6 then
if P.holeRND:random()<.6 then
local initCell={11,14,12,13,21,24}
for _=1,3 do
_=rem(initCell,P:RND(#initCell))
_=rem(initCell,P.holeRND:random(#initCell))
F[math.floor(_/10)][3+_%10]=20
end
else
local initCell={11,12,13,14,21,22,23,24}
rem(initCell,P:RND(5,8))
rem(initCell,P:RND(1,4))
rem(initCell,P.holeRND:random(5,8))
rem(initCell,P.holeRND:random(1,4))
for _=1,6 do
_=rem(initCell,P:RND(#initCell))
_=rem(initCell,P.holeRND:random(#initCell))
F[math.floor(_/10)][3+_%10]=20
end
end

View File

@@ -35,18 +35,18 @@ return{
P.visTime[i]=FREEROW.get(20)
for x=4,7 do F[i][x]=0 end
end
if P:RND()<.6 then
if P.holeRND:random()<.6 then
local initCell={11,14,12,13,21,24}
for _=1,3 do
_=rem(initCell,P:RND(#initCell))
_=rem(initCell,P.holeRND:random(#initCell))
F[math.floor(_/10)][3+_%10]=20
end
else
local initCell={11,12,13,14,21,22,23,24}
rem(initCell,P:RND(5,8))
rem(initCell,P:RND(1,4))
rem(initCell,P.holeRND:random(5,8))
rem(initCell,P.holeRND:random(1,4))
for _=1,6 do
_=rem(initCell,P:RND(#initCell))
_=rem(initCell,P.holeRND:random(#initCell))
F[math.floor(_/10)][3+_%10]=20
end
end

View File

@@ -16,7 +16,7 @@ return{
if D.counter>=t then
D.counter=0
for _=1,4 do
table.insert(P.atkBuffer,{line=generateLine(P:RND(10)),amount=1,countdown=5*t,cd0=5*t,time=0,sent=false,lv=2})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(10)),amount=1,countdown=5*t,cd0=5*t,time=0,sent=false,lv=2})
end
P.atkBufferSum=P.atkBufferSum+4
P.stat.recv=P.stat.recv+4

View File

@@ -16,7 +16,7 @@ return{
if D.counter>=t then
D.counter=0
for _=1,3 do
table.insert(P.atkBuffer,{line=generateLine(P:RND(10)),amount=1,countdown=2*t,cd0=2*t,time=0,sent=false,lv=1})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(10)),amount=1,countdown=2*t,cd0=2*t,time=0,sent=false,lv=1})
end
P.atkBufferSum=P.atkBufferSum+3
P.stat.recv=P.stat.recv+3

View File

@@ -71,7 +71,7 @@ return{
end
FREEROW.discard(height)
P:getNext(wei[P:RND(#wei)])
P:getNext(wei[P.seqRND:random(#wei)])
end
end
end,

View File

@@ -9,7 +9,7 @@ local function check_rise(P)
end
end
for _=1,8-L do
P:garbageRise(13,1,generateLine(P:RND(10)))
P:garbageRise(13,1,generateLine(P.holeRND:random(10)))
end
else
if L==0 then
@@ -17,7 +17,7 @@ local function check_rise(P)
SFX.play('clear')
BG.send(26)
for _=1,8 do
P:garbageRise(13,1,generateLine(P:RND(10)))
P:garbageRise(13,1,generateLine(P.holeRND:random(10)))
end
else
BG.send(#P.clearedRow)
@@ -38,7 +38,7 @@ return{
PLY.newPlayer(1)
local P=PLAYERS[1]
for _=1,8 do
P:garbageRise(13,1,generateLine(P:RND(10)))
P:garbageRise(13,1,generateLine(P.holeRND:random(10)))
end
P.fieldBeneath=0
end,

View File

@@ -45,17 +45,17 @@ return{
end
end
for _=1,5 do
P.field[i][P:RND(10)]=0
P.field[i][P.holeRND:random(10)]=0
end
else
P.field[i]=FREEROW.get(0)
P.visTime[i]=FREEROW.get(30)
for j=1,10 do
if P:RND()>.9 then
if P.holeRND:random()>.9 then
P.field[i][j]=math.random(16)
end
end
P.field[i][P:RND(10)]=0
P.field[i][P.holeRND:random(10)]=0
end
P.field[i].garbage=true
end

View File

@@ -11,7 +11,7 @@ local function task_PC(P)
D.counter=D.counter+1
if D.counter==26 then
local base=PCbase[D.type]
P:pushLineList(base[P:RND(#base)],D.symmetry)
P:pushLineList(base[P.holeRND:random(#base)],D.symmetry)
end
end
end
@@ -23,8 +23,8 @@ local function check(P)
end
else
local type=P.stat.pc<10 and 4 or 5
local L=PClist[type][P:RND(#PClist[type])]
local symmetry=P:RND()>.5
local L=PClist[type][P.holeRND:random(#PClist[type])]
local symmetry=P.holeRND:random()>.5
P.modeData.type=type
P.modeData.symmetry=symmetry
P:pushNextList(L,symmetry)

View File

@@ -13,7 +13,7 @@ local function task_PC(P)
D.counter=D.counter+1
if D.counter==26 then
local base=PCbase[D.type]
P:pushLineList(base[P:RND(#base)],D.symmetry)
P:pushLineList(base[P.holeRND:random(#base)],D.symmetry)
end
YIELD()
end
@@ -26,8 +26,8 @@ local function check(P)
end
else
local type=PCtype[P.stat.pc+1]or 3
local L=PClist[type][P:RND(#PClist[type])]
local symmetry=P:RND()>.5
local L=PClist[type][P.holeRND:random(#PClist[type])]
local symmetry=P.holeRND:random()>.5
P.modeData.type=type
P.modeData.symmetry=symmetry
P:pushNextList(L,symmetry)

View File

@@ -10,7 +10,7 @@ return{
local D=P.modeData
D.timer=D.timer+1
if D.timer>=math.max(60,150-2*D.wave)and P.atkBufferSum<4 then
table.insert(P.atkBuffer,{line=generateLine(P:RND(10)),amount=1,countdown=30,cd0=30,time=0,sent=false,lv=1})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(10)),amount=1,countdown=30,cd0=30,time=0,sent=false,lv=1})
P.atkBufferSum=P.atkBufferSum+1
P.stat.recv=P.stat.recv+1
if D.wave==45 then P:showTextF(text.maxspeed,0,-140,100,'appear',.6)end

View File

@@ -12,10 +12,10 @@ return{
if D.timer>=math.max(60,180-2*D.wave)and P.atkBufferSum<15 then
local s
if D.wave%3<2 then
table.insert(P.atkBuffer,{line=generateLine(P:RND(10)),amount=1,countdown=0,cd0=0,time=0,sent=false,lv=1})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(10)),amount=1,countdown=0,cd0=0,time=0,sent=false,lv=1})
s=1
else
table.insert(P.atkBuffer,{line=generateLine(P:RND(10)),amount=3,countdown=60,cd0=60,time=0,sent=false,lv=2})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(10)),amount=3,countdown=60,cd0=60,time=0,sent=false,lv=2})
s=3
end
P.atkBufferSum=P.atkBufferSum+s

View File

@@ -11,7 +11,7 @@ return{
D.timer=D.timer+1
if D.timer>=math.max(60,150-D.wave)and P.atkBufferSum<20 then
local t=math.max(60,90-D.wave)
table.insert(P.atkBuffer,{line=generateLine(P:RND(10)),amount=4,countdown=t,cd0=t,time=0,sent=false,lv=3})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(10)),amount=4,countdown=t,cd0=t,time=0,sent=false,lv=3})
P.atkBufferSum=P.atkBufferSum+4
P.stat.recv=P.stat.recv+4
if D.wave==60 then P:showTextF(text.maxspeed,0,-140,100,'appear',.6)end

View File

@@ -12,10 +12,10 @@ return{
if D.timer>=math.max(90,180-2*D.wave)and P.atkBufferSum<8 then
local d=D.wave+1
table.insert(P.atkBuffer,
d%4==0 and{line=generateLine(P:RND(10)),amount=1,countdown=60,cd0=60,time=0,sent=false,lv=1}or
d%4==1 and{line=generateLine(P:RND(10)),amount=2,countdown=70,cd0=70,time=0,sent=false,lv=1}or
d%4==2 and{line=generateLine(P:RND(10)),amount=3,countdown=80,cd0=80,time=0,sent=false,lv=2}or
d%4==3 and{line=generateLine(P:RND(10)),amount=4,countdown=90,cd0=90,time=0,sent=false,lv=3}
d%4==0 and{line=generateLine(P.holeRND:random(10)),amount=1,countdown=60,cd0=60,time=0,sent=false,lv=1}or
d%4==1 and{line=generateLine(P.holeRND:random(10)),amount=2,countdown=70,cd0=70,time=0,sent=false,lv=1}or
d%4==2 and{line=generateLine(P.holeRND:random(10)),amount=3,countdown=80,cd0=80,time=0,sent=false,lv=2}or
d%4==3 and{line=generateLine(P.holeRND:random(10)),amount=4,countdown=90,cd0=90,time=0,sent=false,lv=3}
)
P.atkBufferSum=P.atkBufferSum+d%4+1
P.stat.recv=P.stat.recv+d%4+1

View File

@@ -13,10 +13,10 @@ return{
D.timer=D.timer+1
if D.timer>=math.max(300,600-10*D.wave)and P.atkBufferSum<20 then
local t=math.max(300,480-12*D.wave)
table.insert(P.atkBuffer,{line=generateLine(P:RND(10)),amount=4,countdown=t,cd0=t,time=0,sent=false,lv=2})
table.insert(P.atkBuffer,{line=generateLine(P:RND(10)),amount=4,countdown=t,cd0=t,time=0,sent=false,lv=3})
table.insert(P.atkBuffer,{line=generateLine(P:RND(10)),amount=6,countdown=1.2*t,cd0=1.2*t,time=0,sent=false,lv=4})
table.insert(P.atkBuffer,{line=generateLine(P:RND(10)),amount=6,countdown=1.5*t,cd0=1.5*t,time=0,sent=false,lv=5})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(10)),amount=4,countdown=t,cd0=t,time=0,sent=false,lv=2})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(10)),amount=4,countdown=t,cd0=t,time=0,sent=false,lv=3})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(10)),amount=6,countdown=1.2*t,cd0=1.2*t,time=0,sent=false,lv=4})
table.insert(P.atkBuffer,{line=generateLine(P.holeRND:random(10)),amount=6,countdown=1.5*t,cd0=1.5*t,time=0,sent=false,lv=5})
P.atkBufferSum=P.atkBufferSum+20
P.stat.recv=P.stat.recv+20
if D.wave==31 then P:showTextF(text.maxspeed,0,-140,100,'appear',.6)end

View File

@@ -111,7 +111,10 @@ local function newEmptyPlayer(id,mini)
P.draw=ply_draw.norm
end
P.randGen=love.math.newRandomGenerator(GAME.seed)
P.seqRND=love.math.newRandomGenerator(GAME.seed)
P.atkRND=love.math.newRandomGenerator(GAME.seed)
P.holeRND=love.math.newRandomGenerator(GAME.seed)
P.aiRND=love.math.newRandomGenerator(GAME.seed)
P.frameRun=GAME.frameStart
P.alive=true

View File

@@ -121,10 +121,6 @@ end
--------------------------</FX>--------------------------
--------------------------<Method>--------------------------
function Player:RND(a,b)
local R=self.randGen
return R:random(a,b)
end
function Player:newTask(code,...)
local thread=coroutine.create(code)
resume(thread,self,...)
@@ -227,11 +223,11 @@ end
function Player:getHolePos()--Get a good garbage-line hole position
if self.garbageBeneath==0 then
return generateLine(self:RND(10))
return generateLine(self.holeRND:random(10))
else
local p=self:RND(10)
local p=self.holeRND:random(10)
if self.field[1][p]<=0 then
return generateLine(self:RND(10))
return generateLine(self.holeRND:random(10))
end
return generateLine(p)
end
@@ -1336,7 +1332,7 @@ do--Player.drop(self)--Place piece
local M=#self.atker
if M>0 then
for i=1,M do
self:attack(self.atker[i],send,sendTime,generateLine(self:RND(10)))
self:attack(self.atker[i],send,sendTime,generateLine(self.atkRND:random(10)))
end
else
T=randomTarget(self)
@@ -1349,7 +1345,7 @@ do--Player.drop(self)--Place piece
T=randomTarget(self)
end
if T then
self:attack(T,send,sendTime,generateLine(self:RND(10)))
self:attack(T,send,sendTime,generateLine(self.atkRND:random(10)))
end
end
if self.sound and send>3 then SFX.play('emit',min(send,7)*.1)end
@@ -1709,8 +1705,7 @@ function Player:lose(force)
if self.type=='remote'and not force then self.waiting=1e99 return end
if self.life>0 and not force then self:revive()return end
self:die()
local i=TABLE.find(PLY_ALIVE,self)
if i then rem(PLY_ALIVE,i)end
local p=TABLE.find(PLY_ALIVE,self)if p then rem(PLY_ALIVE,p)end
self.result='lose'
if GAME.modeEnv.royaleMode then
self:changeAtk()

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

View File

@@ -176,7 +176,7 @@ scene.widgetList={
WIDGET.newKey{name="refresh", x=300,y=620,w=140,h=140,font=35,code=fetchRoom,hide=function()return fetchTimer>3.26 end},
WIDGET.newKey{name="new", x=500,y=620,w=140,h=140,font=20,code=pressKey"n"},
WIDGET.newKey{name="new2", x=700,y=620,w=140,h=140,font=20,code=pressKey"m"},
WIDGET.newKey{name="join", x=900,y=620,w=140,h=140,font=40,code=pressKey"return",hide=function()return #NET.roomList==0 or NET.getlock('enterRoom') end},
WIDGET.newKey{name="join", x=900,y=620,w=140,h=140,font=40,code=pressKey"return",hide=function()return #NET.roomList==0 or NET.getlock('enterRoom')end},
WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,font=40,code=backScene},
}