simplify sequence generator
This commit is contained in:
@@ -1,75 +1,74 @@
|
||||
local ins=table.insert
|
||||
local yield=coroutine.yield
|
||||
return {
|
||||
env={
|
||||
drop=20,lock=60,
|
||||
sequence=function(P)
|
||||
for _=1,3 do P:getNext(7) end
|
||||
sequence=function(seqRND)
|
||||
local field,stat
|
||||
for _=1,3 do field,stat=yield(7) end
|
||||
while true do
|
||||
coroutine.yield()
|
||||
if not P.nextQueue[1] then
|
||||
local height=TABLE.new(0,10)
|
||||
local max=#P.field
|
||||
if max>0 then
|
||||
-- Get heights
|
||||
for x=1,10 do
|
||||
local h=max
|
||||
while P.field[h][x]==0 and h>1 do
|
||||
h=h-1
|
||||
end
|
||||
height[x]=h
|
||||
end
|
||||
else
|
||||
for x=1,10 do
|
||||
height[x]=0
|
||||
local height=TABLE.new(0,10)
|
||||
local max=#field
|
||||
if max>0 then
|
||||
-- Get heights
|
||||
for x=1,10 do
|
||||
local h=max
|
||||
while field[h][x]==0 and h>1 do
|
||||
h=h-1
|
||||
end
|
||||
height[x]=h
|
||||
end
|
||||
height[11]=999
|
||||
|
||||
local wei={1,1,2,2,3,4}
|
||||
local d=0
|
||||
for i=1,10 do
|
||||
d=d+height[i]
|
||||
else
|
||||
for x=1,10 do
|
||||
height[x]=0
|
||||
end
|
||||
if d<40 or P.stat.row>2*42 then-- Low field or almost win, give SZO
|
||||
for _=1,4 do
|
||||
ins(wei,1)
|
||||
ins(wei,2)
|
||||
ins(wei,6)
|
||||
end
|
||||
else
|
||||
-- Give I when no hole
|
||||
local tempDeltaHei=-999-- Height difference
|
||||
for x=2,11 do
|
||||
local deltaHei=height[x]-height[x-1]
|
||||
if tempDeltaHei<-2 and deltaHei>2 then
|
||||
break
|
||||
elseif x==11 then
|
||||
for _=1,3 do ins(wei,7) end
|
||||
else
|
||||
tempDeltaHei=deltaHei
|
||||
end
|
||||
end
|
||||
|
||||
-- Give O when no d=0/give T when no d=1
|
||||
local flatCount=0-- d=0 count
|
||||
local stairCount=0-- d=1 count
|
||||
for x=2,10 do
|
||||
local _=height[x]-height[x-1]
|
||||
if _==0 then
|
||||
flatCount=flatCount+1
|
||||
elseif _==1 or _==-1 then
|
||||
stairCount=stairCount+1
|
||||
end
|
||||
end
|
||||
if flatCount<3 then
|
||||
for _=1,3 do ins(wei,6) end
|
||||
end
|
||||
if stairCount<3 then
|
||||
for _=1,4 do ins(wei,5) end
|
||||
end
|
||||
end
|
||||
P:getNext(wei[P.seqRND:random(#wei)])
|
||||
end
|
||||
height[11]=999
|
||||
|
||||
local wei={1,1,2,2,3,4}
|
||||
local d=0
|
||||
for i=1,10 do
|
||||
d=d+height[i]
|
||||
end
|
||||
if d<40 or stat.row>2*42 then-- Low field or almost win, give SZO
|
||||
for _=1,4 do
|
||||
ins(wei,1)
|
||||
ins(wei,2)
|
||||
ins(wei,6)
|
||||
end
|
||||
else
|
||||
-- Give I when no hole
|
||||
local tempDeltaHei=-999-- Height difference
|
||||
for x=2,11 do
|
||||
local deltaHei=height[x]-height[x-1]
|
||||
if tempDeltaHei<-2 and deltaHei>2 then
|
||||
break
|
||||
elseif x==11 then
|
||||
for _=1,3 do ins(wei,7) end
|
||||
else
|
||||
tempDeltaHei=deltaHei
|
||||
end
|
||||
end
|
||||
|
||||
-- Give O when no d=0/give T when no d=1
|
||||
local flatCount=0-- d=0 count
|
||||
local stairCount=0-- d=1 count
|
||||
for x=2,10 do
|
||||
local _=height[x]-height[x-1]
|
||||
if _==0 then
|
||||
flatCount=flatCount+1
|
||||
elseif _==1 or _==-1 then
|
||||
stairCount=stairCount+1
|
||||
end
|
||||
end
|
||||
if flatCount<3 then
|
||||
for _=1,3 do ins(wei,6) end
|
||||
end
|
||||
if stairCount<3 then
|
||||
for _=1,4 do ins(wei,5) end
|
||||
end
|
||||
end
|
||||
field,stat=yield(wei[seqRND:random(#wei)])
|
||||
end
|
||||
end,
|
||||
nextCount=1,holdCount=0,
|
||||
|
||||
Reference in New Issue
Block a user