Commit 70ab2010 authored by Vury Leo's avatar Vury Leo

tuning 白の枢機竜

parent 6c193bc3
...@@ -3646,51 +3646,77 @@ function Fusion.StrictGroup(e,leftovers,mg_base,grp,tc,fgoalcheck,chkf) ...@@ -3646,51 +3646,77 @@ function Fusion.StrictGroup(e,leftovers,mg_base,grp,tc,fgoalcheck,chkf)
return Fusion.FinalCheck(e,mg,tc,fgoalcheck,chkf) return Fusion.FinalCheck(e,mg,tc,fgoalcheck,chkf)
end end
-- Search mode: find *some* size‐grp.min subset that passes -- Search mode: find *some* subset of size [grp.min…grp.max] that passes
function Fusion.SearchGroup(e,leftovers,mg_base,grp,tc,fgoalcheck,chkf) function Fusion.SearchGroup(e,leftovers,mg_base,grp,tc,fgoalcheck,chkf)
-- filter leftovers by grp.filter -- pre‐filter by grp.filter
local matched={} local matched={}
for _,c in ipairs(leftovers) do for _,c in ipairs(leftovers) do
if not grp.filter or grp.filter(c,tc) then if not grp.filter or grp.filter(c,tc) then
table.insert(matched,c) table.insert(matched,c)
end end
end end
if #matched<grp.min then return false end if #matched<grp.min then
return false
local comb={} end
local function dfs_comb(start,depth)
if depth>grp.min then -- early UniqueByMatching prune for max size
-- subset built in comb[1..grp.min] if grp.unique_by then
local subG=Group.FromCards(table.unpack(comb)) local matcher=Fusion.UniqueByMatching(grp.unique_by,grp.min)
-- has_same if not matcher(matched) then
if grp.has_same and not Fusion.CheckHasSame(grp,subG,e) then return false
return false end
end end
-- unique_by
local comb={}
local function dfs(start,depth)
-- If we have at least grp.min cards, test this subset immediately
if depth>=grp.min then
-- build subset group and merged material group
local subG=Group.FromCards(table.unpack(comb,1,depth))
local mg_tmp=mg_base:Clone()
mg_tmp:Merge(subG)
-- has_same check
local ok_same=not grp.has_same or Fusion.CheckHasSame(grp,subG,e)
-- unique_by check
local ok_unique=true
if grp.unique_by then if grp.unique_by then
local matcher=Fusion.UniqueByMatching(grp.unique_by,grp.min) local matcher=Fusion.UniqueByMatching(grp.unique_by,depth)
if not matcher(comb) then ok_unique=matcher(comb)
return false
end
end end
-- merge & final -- final fusion checks
local mg=mg_base:Clone() if ok_same and ok_unique and Fusion.FinalCheck(e,mg_tmp,tc,fgoalcheck,chkf) then
mg:Merge(subG)
return Fusion.FinalCheck(e,mg,tc,fgoalcheck,chkf)
end
for i=start,#matched-(grp.min-depth)+1 do
comb[depth]=matched[i]
if dfs_comb(i+1,depth+1) then
return true return true
end end
end end
return false
end -- Stop recursing if we've hit grp.max
if depth==grp.max then
return false
end
-- Prune if not enough cards remain to reach grp.min
if #matched-start+1+depth<grp.min then
return false
end
return dfs_comb(1,1) -- Otherwise, try adding one more card
for i=start,#matched do
comb[depth+1]=matched[i]
if dfs(i+1,depth+1) then
return true
end
comb[depth+1]=nil
end
return false
end
-- kick off the DFS
return dfs(1,0)
end end
-- Shared has_same checker (bitmask or key‐list) -- Shared has_same checker (bitmask or key‐list)
function Fusion.CheckHasSame(grp,group_obj,e) function Fusion.CheckHasSame(grp,group_obj,e)
local cards={} local cards={}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment