Commit ce84e366 authored by mercury233's avatar mercury233

update OnSelectSum

parent 5bbaebde
using YGOSharp.OCGWrapper.Enums;
using System.Linq;
using System.Collections.Generic;
namespace WindBot.Game.AI
......@@ -174,5 +175,12 @@ namespace WindBot.Game.AI
}
return null;
}
public static IEnumerable<IEnumerable<T>> GetCombinations<T>(this IEnumerable<T> elements, int k)
{
return k == 0 ? new[] { new T[0] } :
elements.SelectMany((e, i) =>
elements.Skip(i + 1).GetCombinations(k - 1).Select(c => (new[] { e }).Concat(c)));
}
}
}
\ No newline at end of file
......@@ -221,74 +221,20 @@ namespace WindBot.Game.AI.Decks
public override IList<ClientCard> OnSelectSum(IList<ClientCard> cards, int sum, int min, int max, bool mode)
{
Logger.DebugWriteLine("OnSelectSum " + cards.Count + " " + sum + " " + min + " " + max);
if (sum > 12 || !mode)
if (sum != 8 || !mode)
return null;
IList<ClientCard> avail = new List<ClientCard>();
foreach (ClientCard card in cards)
{
// clone
avail.Add(card);
}
IList<ClientCard> selected = new List<ClientCard>();
int trysum = 0;
if (使用过的青眼亚白龙.Count > 0 && avail.IndexOf(使用过的青眼亚白龙[0]) > 0)
{
Logger.DebugWriteLine("优先用使用过的亚白龙同调.");
ClientCard card = 使用过的青眼亚白龙[0];
使用过的青眼亚白龙.Remove(card);
avail.Remove(card);
selected.Add(card);
trysum = card.Level;
if (trysum == sum)
{
Logger.DebugWriteLine("直接选择了使用过的青眼亚白龙");
return selected;
}
}
foreach (ClientCard card in cards)
{
// try level equal
Logger.DebugWriteLine("同调素材可以选择: " + card.Name);
if (card.Level == sum)
{
Logger.DebugWriteLine("直接选择了" + card.Name);
return new[] { card };
}
// try level add
if (trysum + card.Level > sum)
{
Logger.DebugWriteLine("跳过了" + card.Name);
continue;
}
selected.Add(card);
trysum += card.Level;
Logger.DebugWriteLine("添加" + card.Name);
Logger.DebugWriteLine(trysum + " selected " + sum);
if (trysum == sum)
{
return selected;
}
}
IList<ClientCard> selected2 = new List<ClientCard>();
foreach (ClientCard card in selected)
{
// clone
selected2.Add(card);
}
foreach (ClientCard card in selected)
foreach (ClientCard 亚白龙 in 使用过的青眼亚白龙)
{
// try level sub
selected2.Remove(card);
trysum -= card.Level;
Logger.DebugWriteLine("排除" + card.Name);
Logger.DebugWriteLine(trysum + " selected2 " + sum);
if (trysum == sum)
if (cards.IndexOf(亚白龙) > 0)
{
return selected2;
使用过的青眼亚白龙.Remove(亚白龙);
Logger.DebugWriteLine("选择了使用过的青眼亚白龙");
return new[] { 亚白龙 };
}
}
// try all
return cards;
return null;
}
public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
......
......@@ -157,7 +157,7 @@ namespace WindBot.Game
public IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max, bool cancelable)
{
// Check for the executor.
IList<ClientCard> result = Executor.OnSelectCard(cards, min,max,cancelable);
IList<ClientCard> result = Executor.OnSelectCard(cards, min, max, cancelable);
if (result != null)
return result;
......@@ -376,10 +376,12 @@ namespace WindBot.Game
return selected;
}
if (mode)
{
// equal
if (min <= 1)
{
foreach (ClientCard card in cards)
{
//Logger.WriteLine("OpParam1 " + card.OpParam1 + " OpParam2 " + card.OpParam2 + " sum " + sum);
// try special level
if (card.OpParam2 == sum)
{
......@@ -394,48 +396,39 @@ namespace WindBot.Game
return new[] { card };
}
}
selected = new List<ClientCard>();
int trysum = 0;
foreach (ClientCard card in cards)
}
int i = (min <= 1) ? 2 : min;
while (i <= max && i <= cards.Count)
{
// try level add
if (trysum + card.OpParam1 > sum)
IEnumerable<IEnumerable<ClientCard>> combos = CardContainer.GetCombinations(cards, i);
foreach (IEnumerable<ClientCard> combo in combos)
{
continue;
}
selected.Add(card);
trysum += card.OpParam1;
//Logger.DebugWriteLine(card.Id + "");
//Logger.DebugWriteLine(trysum + " selected " + sum);
if (trysum == sum)
Logger.DebugWriteLine("--");
int s1 = 0, s2 = 0;
selected = new List<ClientCard>();
foreach (ClientCard card in combo)
{
return selected;
}
s1 += card.OpParam1;
s2 += (card.OpParam2 != 0) ? card.OpParam2 : card.OpParam1;
selected.Add(card);
}
IList<ClientCard> selected2 = new List<ClientCard>();
foreach (ClientCard card in selected)
if (s1 == sum || s2 == sum)
{
// clone
selected2.Add(card);
return selected;
}
foreach (ClientCard card in selected)
{
// try level sub
selected2.Remove(card);
trysum -= card.OpParam1;
//Logger.DebugWriteLine(card.Id + "");
//Logger.DebugWriteLine(trysum + " selected2 " + sum);
if (trysum == sum)
{
return selected2;
}
i++;
}
}
else
{
// larger
if (min <= 1)
{
foreach (ClientCard card in cards)
{
//Logger.WriteLine("OpParam1 " + card.OpParam1 + " OpParam2 " + card.OpParam2 + " sum " + sum);
// try special level
if (card.OpParam2 >= sum)
{
......@@ -450,41 +443,35 @@ namespace WindBot.Game
return new[] { card };
}
}
}
int i = (min <= 1) ? 2 : min;
while (i <= max && i <= cards.Count)
{
IEnumerable<IEnumerable<ClientCard>> combos = CardContainer.GetCombinations(cards, i);
foreach (IEnumerable<ClientCard> combo in combos)
{
Logger.DebugWriteLine("----");
int s1 = 0, s2 = 0;
selected = new List<ClientCard>();
int trysum = 0;
foreach (ClientCard card in cards)
foreach (ClientCard card in combo)
{
// try level add
s1 += card.OpParam1;
s2 += (card.OpParam2 != 0) ? card.OpParam2 : card.OpParam1;
selected.Add(card);
trysum += card.OpParam1;
//Logger.DebugWriteLine(card.Id + "");
//Logger.DebugWriteLine(trysum + " selected " + sum);
if (trysum >= sum)
{
return selected;
}
}
IList<ClientCard> selected2 = new List<ClientCard>();
foreach (ClientCard card in selected)
if (s1 >= sum || s2 >= sum)
{
// clone
selected2.Add(card);
return selected;
}
foreach (ClientCard card in selected)
{
// try level sub
selected2.Remove(card);
trysum -= card.OpParam1;
//Logger.DebugWriteLine(card.Id + "");
//Logger.DebugWriteLine(trysum + " selected2 " + sum);
if (trysum >= sum)
{
return selected2;
}
i++;
}
}
// try all
return cards;
Logger.WriteErrorLine("Fail to select sum.");
return null;
}
/// <summary>
......
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