Skip to content

Commit

Permalink
气泡序列生成流程换新为方块的
Browse files Browse the repository at this point in the history
修改气泡序列名称
添加更多气泡序列类型
  • Loading branch information
MrZ626 committed May 4, 2024
1 parent b394e77 commit 365fdd6
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 27 deletions.
73 changes: 52 additions & 21 deletions assets/game/mechanicLib/puyo/sequence.lua
Original file line number Diff line number Diff line change
@@ -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
54 changes: 48 additions & 6 deletions assets/game/puyoPlayer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ function PP:freshDelay(reason)
end
function PP:freshNextQueue()
while #self.nextQueue<max(self.settings.nextSlot,1) do
local shape=self:seqGen()
local shape=self:seqGen(self.seqData)
if shape then self:getPuyo(shape) end
end
end
Expand Down Expand Up @@ -445,7 +445,7 @@ function PP:getPuyo(mat)

local puyo={
id=self.pieceCount,
shapeH=#mat[1],
size=max(#mat,#mat[1]),
direction=0,
matrix=mat,
}
Expand Down Expand Up @@ -550,7 +550,7 @@ function PP:rotate(dir,ifInit)
local cb=self.hand.matrix
local icb=TABLE.rotate(cb,dir)

local kicks=PRS[self.hand.shapeH][self.hand.direction][dir]
local kicks=PRS[self.hand.size][self.hand.direction][dir]
for n=1,#kicks do
local ix,iy=self.handX+kicks[n][1],self.handY+kicks[n][2]
if not self:ifoverlap(icb,ix,iy) then
Expand Down Expand Up @@ -1227,13 +1227,15 @@ local baseEnv={
lockoutH=1e99,
deathH=1e99,
voidH=620,
connH=12, -- Default to 12
connH=4, -- Default to 12

-- Clear
clearGroupSize=4,

-- Sequence
seqType='double4color',
seqType='twin_2S4C',
maxOpeningLength=2,
maxOpeningColor=3,
nextSlot=6,

-- Delay
Expand Down Expand Up @@ -1344,8 +1346,48 @@ function PP:initialize()
self.garbageBuffer={}

self.nextQueue={}
self.seqGen=coroutine.wrap(mechLib.puyo.sequence[self.settings.seqType] or self.settings.seqType)
self.seqData={}
self.seqGen=mechLib.puyo.sequence[self.settings.seqType] or self.settings.seqType
assert(self:seqGen(self.seqData,true)==nil,"First call of sequence generator must return nil")
self:freshNextQueue()
while true do
-- Collect all cells in first N pieces
local cells={}
for n=1,min(self.settings.maxOpeningLength,#self.nextQueue) do
local mat=self.nextQueue[n].matrix
for y=1,#mat do for x=1,#mat[1] do
local c=mat[y][x]
if c then
ins(cells,{n,y,x,c.color})
end
end end
end

-- Count colors
local colors={}
for i=1,#cells do
local c=cells[i]
local dictKey='mrz'..c[4]
if not colors[dictKey] then
colors[dictKey]={c[4],0}
ins(colors,colors[dictKey])
end
colors[dictKey][2]=colors[dictKey][2]+1
end

-- Finish when color count is less enough
if #colors<=1 or #colors<=self.settings.maxOpeningColor then break end

-- Merge the rarest two colors
table.sort(colors,function(a,b) return a[2]<b[2] end)
local orig,dest=colors[1][1],colors[2][1]
for i=1,#cells do
if cells[i][4]==orig then
self.nextQueue[cells[i][1]].matrix[cells[i][2]][cells[i][3]].color=dest
end
end
-- print('Merged color '..orig..' to '..dest)
end

self.dropTimer=0
self.lockTimer=0
Expand Down

0 comments on commit 365fdd6

Please sign in to comment.