diff --git a/assets/game/mechanicLib/puyo/sequence.lua b/assets/game/mechanicLib/puyo/sequence.lua index 41a29c4b..365dbef5 100644 --- a/assets/game/mechanicLib/puyo/sequence.lua +++ b/assets/game/mechanicLib/puyo/sequence.lua @@ -1,34 +1,65 @@ local ins,rem=table.insert,table.remove +-- Fill list when empty, with source +---@return boolean #True when filled +local function supply(list,src,rep) + if not list[1] then + for _=1,rep or 1 do + TABLE.connect(list,src) + end + return true + end + return false +end + ---@type Techmino.Mech.puyo local sequence={} -function sequence.none() - while true do coroutine.yield() end +---@param P Techmino.Player.puyo +---@param d table cached data of generator +---@param init boolean true if this is the first initializating call +---@diagnostic disable-next-line +function sequence.none(P,d,init) end -function sequence.double3color(P) - local l={} - while true do - if not l[1] then for i=1,3 do for j=1,3 do ins(l,{{i},{j}}) end end end - coroutine.yield(rem(l,P:random(#l))) - end -end +-------------------------------------------------------------- +-- Twin -function sequence.double4color(P) - local l={} - while true do - if not l[1] then for i=1,4 do for j=1,4 do ins(l,{{i},{j}}) end end end - coroutine.yield(rem(l,P:random(#l))) - end +-- Simply all permutations +local TwinSet={} +for i=1,8 do + TwinSet[i]={} + for x=1,i do for y=1,i do + ins(TwinSet[i],{{x},{y}}) + end end end - -function sequence.double5color(P) - local l={} - while true do - if not l[1] then for i=1,5 do for j=1,5 do ins(l,{{i},{j}}) end end end - coroutine.yield(rem(l,P:random(#l))) +for _,bagCount in next,{2,4,8} do for colors=3,8 do + sequence['twin_'..bagCount..'S'..colors..'C']=function(P,d,init) + if init then d.bag={} return end + supply(d.bag,TwinSet[colors],bagCount) + return rem(d.bag,P:random(#d.bag)) end +end end + +-- No repeat in one set +local NRTwinSet={} +for i=1,8 do + NRTwinSet[i]={} + for x=1,i do for y=1,x do + ins(NRTwinSet[i],{{x},{y}}) + end end end +for _,bagCount in next,{2,4,8} do for colors=3,8 do + sequence['twin_'..bagCount..'S'..colors..'NRC']=function(P,d,init) + if init then d.bag={} return end + supply(d.bag,NRTwinSet[colors],bagCount) + return rem(d.bag,P:random(#d.bag)) + end +end end + +-------------------------------------------------------------- +-- Multi + +-- TODO return sequence diff --git a/assets/game/puyoPlayer.lua b/assets/game/puyoPlayer.lua index 2c4e594b..c399892e 100644 --- a/assets/game/puyoPlayer.lua +++ b/assets/game/puyoPlayer.lua @@ -408,7 +408,7 @@ function PP:freshDelay(reason) end function PP:freshNextQueue() while #self.nextQueue