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
local comb={}
local function dfs_comb(start,depth)
if depth>grp.min then
-- subset built in comb[1..grp.min]
local subG=Group.FromCards(table.unpack(comb))
-- has_same
if grp.has_same and not Fusion.CheckHasSame(grp,subG,e) then
return false return false
end end
-- unique_by
-- early UniqueByMatching prune for max size
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,grp.min)
if not matcher(comb) then if not matcher(matched) then
return false return false
end end
end end
-- merge & final
local mg=mg_base:Clone() local comb={}
mg:Merge(subG)
return Fusion.FinalCheck(e,mg,tc,fgoalcheck,chkf) 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
local matcher=Fusion.UniqueByMatching(grp.unique_by,depth)
ok_unique=matcher(comb)
end
-- final fusion checks
if ok_same and ok_unique and Fusion.FinalCheck(e,mg_tmp,tc,fgoalcheck,chkf) then
return true
end
end
-- Stop recursing if we've hit grp.max
if depth==grp.max then
return false
end end
for i=start,#matched-(grp.min-depth)+1 do -- Prune if not enough cards remain to reach grp.min
comb[depth]=matched[i] if #matched-start+1+depth<grp.min then
if dfs_comb(i+1,depth+1) then return false
end
-- 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 return true
end end
comb[depth+1]=nil
end end
return false return false
end end
return dfs_comb(1,1) -- 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