Commit aa4ff6cc authored by mercury233's avatar mercury233 Committed by GitHub

update Group.SelectSubGroup (#1151)

Skip cards which had been proved to be selectable or not selectable.
parent 2612ab25
...@@ -2008,6 +2008,7 @@ function Auxiliary.GetMultiLinkedZone(tp) ...@@ -2008,6 +2008,7 @@ function Auxiliary.GetMultiLinkedZone(tp)
end end
return multi_linked_zone return multi_linked_zone
end end
Auxiliary.SubGroupCaptured=nil
function Auxiliary.CheckGroupRecursive(c,sg,g,f,min,max,ext_params) function Auxiliary.CheckGroupRecursive(c,sg,g,f,min,max,ext_params)
sg:AddCard(c) sg:AddCard(c)
local res=(#sg>=min and #sg<=max and f(sg,table.unpack(ext_params))) local res=(#sg>=min and #sg<=max and f(sg,table.unpack(ext_params)))
...@@ -2015,6 +2016,18 @@ function Auxiliary.CheckGroupRecursive(c,sg,g,f,min,max,ext_params) ...@@ -2015,6 +2016,18 @@ function Auxiliary.CheckGroupRecursive(c,sg,g,f,min,max,ext_params)
sg:RemoveCard(c) sg:RemoveCard(c)
return res return res
end end
function Auxiliary.CheckGroupRecursiveCapture(c,sg,g,f,min,max,ext_params)
sg:AddCard(c)
local res=#sg>=min and #sg<=max and f(sg,table.unpack(ext_params))
if res then
Auxiliary.SubGroupCaptured:Clear()
Auxiliary.SubGroupCaptured:Merge(sg)
else
res=#sg<max and g:IsExists(Auxiliary.CheckGroupRecursiveCapture,1,sg,sg,g,f,min,max,ext_params)
end
sg:RemoveCard(c)
return res
end
function Group.CheckSubGroup(g,f,min,max,...) function Group.CheckSubGroup(g,f,min,max,...)
local min=min or 1 local min=min or 1
local max=max or #g local max=max or #g
...@@ -2023,9 +2036,15 @@ function Group.CheckSubGroup(g,f,min,max,...) ...@@ -2023,9 +2036,15 @@ function Group.CheckSubGroup(g,f,min,max,...)
local sg=Duel.GrabSelectedCard() local sg=Duel.GrabSelectedCard()
if #sg>max or #(g+sg)<min or #sg==max and not f(sg,...) then return false end if #sg>max or #(g+sg)<min or #sg==max and not f(sg,...) then return false end
if #sg>=min and #sg<=max and f(sg,...) then return true end if #sg>=min and #sg<=max and f(sg,...) then return true end
return g:IsExists(Auxiliary.CheckGroupRecursive,1,sg,sg,g,f,min,max,ext_params) local eg=g:Clone()
for c in aux.Next(g-sg) do
if Auxiliary.CheckGroupRecursive(c,sg,eg,f,min,max,ext_params) then return true end
eg:RemoveCard(c)
end
return false
end end
function Group.SelectSubGroup(g,tp,f,cancelable,min,max,...) function Group.SelectSubGroup(g,tp,f,cancelable,min,max,...)
Auxiliary.SubGroupCaptured=Group.CreateGroup()
local min=min or 1 local min=min or 1
local max=max or #g local max=max or #g
local ext_params={...} local ext_params={...}
...@@ -2038,7 +2057,18 @@ function Group.SelectSubGroup(g,tp,f,cancelable,min,max,...) ...@@ -2038,7 +2057,18 @@ function Group.SelectSubGroup(g,tp,f,cancelable,min,max,...)
sg:Merge(fg) sg:Merge(fg)
local finish=(#sg>=min and #sg<=max and f(sg,...)) local finish=(#sg>=min and #sg<=max and f(sg,...))
while #sg<max do while #sg<max do
local cg=g:Filter(Auxiliary.CheckGroupRecursive,sg,sg,g,f,min,max,ext_params) local cg=Group.CreateGroup()
local eg=g:Clone()
for c in aux.Next(g-sg) do
if not cg:IsContains(c) then
if Auxiliary.CheckGroupRecursiveCapture(c,sg,eg,f,min,max,ext_params) then
cg:Merge(Auxiliary.SubGroupCaptured)
else
eg:RemoveCard(c)
end
end
end
cg:Sub(sg)
finish=(#sg>=min and #sg<=max and f(sg,...)) finish=(#sg>=min and #sg<=max and f(sg,...))
if #cg==0 then break end if #cg==0 then break end
local cancel=not finish and cancelable local cancel=not finish and cancelable
......
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