Commit 2c21cc43 authored by SherryChaos's avatar SherryChaos

fix performance issues in selectSum

parent e3992f78
...@@ -4713,28 +4713,34 @@ namespace MDPro3 ...@@ -4713,28 +4713,34 @@ namespace MDPro3
return new int[] { sum1, sum2 }; return new int[] { sum1, sum2 };
} }
public static bool CheckSelectable(List<GameCard> cards, GameCard card, List<GameCard> selectedCards, int max) public static bool CheckSelectable(List<GameCard> cards, GameCard card, List<GameCard> selectedCards, int max, List<GameCard> unselectables = null)
{ {
if(selectedCards.Count >= max) if(selectedCards.Count >= max)
return false; return false;
bool returnValue = false; bool returnValue = false;
var sum = GetSelectLevelSum(selectedCards); var sum = GetSelectLevelSum(selectedCards);
if(unselectables == null)
unselectables = new List<GameCard>();
foreach(var c in cards)
if(!selectedCards.Contains(c))
if (!unselectables.Contains(c))
if(c != card)
if (sum[0] + c.levelForSelect_1 > Program.I().ocgcore.ES_level || sum[1] + c.levelForSelect_2 > Program.I().ocgcore.ES_level)
unselectables.Add(c);
if (sum[0] + card.levelForSelect_1 == Program.I().ocgcore.ES_level || sum[1] + card.levelForSelect_2 == Program.I().ocgcore.ES_level) if (sum[0] + card.levelForSelect_1 == Program.I().ocgcore.ES_level || sum[1] + card.levelForSelect_2 == Program.I().ocgcore.ES_level)
return true; return true;
else else
{ {
var newSelectedCards = new List<GameCard>(); var newSelectedCards = new List<GameCard>(selectedCards) { card };
if (selectedCards != null)
foreach (var c in selectedCards)
newSelectedCards.Add(c);
newSelectedCards.Add(card);
foreach (var c in cards) foreach (var c in cards)
if (!newSelectedCards.Contains(c)) if(!unselectables.Contains(c))
{ if (!newSelectedCards.Contains(c))
returnValue = CheckSelectable(cards, c, newSelectedCards, max); {
if (returnValue) returnValue = CheckSelectable(cards, c, newSelectedCards, max, unselectables);
return true; if (returnValue)
} return true;
}
} }
return returnValue; return returnValue;
} }
......
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