From b4be31361ef756064210051229367917b24cb0dd Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Sat, 8 May 2021 13:14:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3hisPool=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E7=94=9F=E6=88=90=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/player/seqGenerators.lua | 78 ++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/parts/player/seqGenerators.lua b/parts/player/seqGenerators.lua index 7e272907..21524ad4 100644 --- a/parts/player/seqGenerators.lua +++ b/parts/player/seqGenerators.lua @@ -45,49 +45,61 @@ local seqGenerators={ hisPool=function(P,seq0) local len=#seq0 local hisLen=ceil(len*.5) - local poolLen=5*len + local history=TABLE.new(0,hisLen)--Indexes of mino-index - local history=TABLE.new(0,hisLen)--Indexes of pool + local poolLen=5*len 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 res=pool[r] + + --Find droughtest(s) minoes + local droughtList={1}--Droughtst minoes' indexes of seq0 + local maxTime=droughtTimes[1] + for i=2,len do + if droughtTimes[i]>maxTime then + maxTime=droughtTimes[i] + if #droughtList==1 then droughtList[1]=i else droughtList={i}end + elseif droughtTimes[i]==maxTime then + ins(droughtList,i) + end + end + + --Update droughtTimes + for i=1,len do droughtTimes[i]=droughtTimes[i]+1 end + droughtTimes[res]=0 + + --Update pool + -- print("Rem "..res) + pool[r]=droughtList[P:RND(#droughtList)] + -- print("Add "..pool[r]) + + return res + end while true do while #P.nextQueue<6 do - --Roll mino - local r--Random index of pool - for _=1,hisLen do - r=P:RND(poolLen) - for i=1,hisLen do - if pool[r]==history[i]then - goto CONTINUE_rollAgain - end + -- print"======================" + --Pick a mino from pool + local tryTime=0 + ::REPEAT_pickAgain:: + local r=poolPick()--Random mino-index in pool + for i=1,len do + if r==history[i]then + tryTime=tryTime+1 + if tryTimemaxTime then - maxTime=droughtTimes[i] - if #droughtList==1 then droughtList[1]=i else droughtList={i}end - elseif droughtTimes[i]==maxTime then - ins(droughtList,i) - end - end - - --Update droughtTimes - for i=1,len do droughtTimes[i]=droughtTimes[i]+1 end - droughtTimes[pool[r]]=0 - - --Update pool - pool[r]=droughtList[P:RND(#droughtList)] + if history[1]~=0 then P:getNext(seq0[r])end + rem(history,1)ins(history,r) + -- print("Player GET: "..r) + -- print("History: "..table.concat(history,",")) + -- local L={"","","","","","","",} + -- for _,v in next,pool do L[v]=L[v].."+"end + -- for i=1,#L do print(i,droughtTimes[i],L[i])end end yield() end