修正hisPool序列生成算法

This commit is contained in:
MrZ626
2021-05-08 13:14:01 +08:00
parent b11e5e12d3
commit b4be31361e

View File

@@ -45,49 +45,61 @@ local seqGenerators={
hisPool=function(P,seq0) hisPool=function(P,seq0)
local len=#seq0 local len=#seq0
local hisLen=ceil(len*.5) 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 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 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 true do
while #P.nextQueue<6 do while #P.nextQueue<6 do
--Roll mino -- print"======================"
local r--Random index of pool --Pick a mino from pool
for _=1,hisLen do local tryTime=0
r=P:RND(poolLen) ::REPEAT_pickAgain::
for i=1,hisLen do local r=poolPick()--Random mino-index in pool
if pool[r]==history[i]then for i=1,len do
goto CONTINUE_rollAgain if r==history[i]then
end tryTime=tryTime+1
if tryTime<hisLen then goto REPEAT_pickAgain end
end end
do break end
::CONTINUE_rollAgain::
end end
--Give mino to player & update history --Give mino to player & update history
if history[1]~=0 then P:getNext(seq0[pool[r]])end if history[1]~=0 then P:getNext(seq0[r])end
rem(history,1)ins(history,pool[r]) rem(history,1)ins(history,r)
-- print("Player GET: "..r)
--Find droughtest(s) minoes -- print("History: "..table.concat(history,","))
local droughtList={1}--Droughtst minoes' indexes of seq0 -- local L={"","","","","","","",}
local maxTime=droughtTimes[1] -- for _,v in next,pool do L[v]=L[v].."+"end
for i=2,len do -- for i=1,#L do print(i,droughtTimes[i],L[i])end
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[pool[r]]=0
--Update pool
pool[r]=droughtList[P:RND(#droughtList)]
end end
yield() yield()
end end