Commit ce84e366 authored by mercury233's avatar mercury233

update OnSelectSum

parent 5bbaebde
using YGOSharp.OCGWrapper.Enums; using YGOSharp.OCGWrapper.Enums;
using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
namespace WindBot.Game.AI namespace WindBot.Game.AI
...@@ -174,5 +175,12 @@ namespace WindBot.Game.AI ...@@ -174,5 +175,12 @@ namespace WindBot.Game.AI
} }
return null; 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 ...@@ -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) public override IList<ClientCard> OnSelectSum(IList<ClientCard> cards, int sum, int min, int max, bool mode)
{ {
Logger.DebugWriteLine("OnSelectSum " + cards.Count + " " + sum + " " + min + " " + max); Logger.DebugWriteLine("OnSelectSum " + cards.Count + " " + sum + " " + min + " " + max);
if (sum > 12 || !mode) if (sum != 8 || !mode)
return null; return null;
IList<ClientCard> avail = new List<ClientCard>();
foreach (ClientCard card in cards) foreach (ClientCard 亚白龙 in 使用过的青眼亚白龙)
{
// 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)
{ {
// try level sub if (cards.IndexOf(亚白龙) > 0)
selected2.Remove(card);
trysum -= card.Level;
Logger.DebugWriteLine("排除" + card.Name);
Logger.DebugWriteLine(trysum + " selected2 " + sum);
if (trysum == sum)
{ {
return selected2; 使用过的青眼亚白龙.Remove(亚白龙);
Logger.DebugWriteLine("选择了使用过的青眼亚白龙");
return new[] { 亚白龙 };
} }
} }
// try all
return cards; return null;
} }
public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender) public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender)
......
...@@ -157,7 +157,7 @@ namespace WindBot.Game ...@@ -157,7 +157,7 @@ namespace WindBot.Game
public IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max, bool cancelable) public IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min, int max, bool cancelable)
{ {
// Check for the executor. // 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) if (result != null)
return result; return result;
...@@ -376,10 +376,12 @@ namespace WindBot.Game ...@@ -376,10 +376,12 @@ namespace WindBot.Game
return selected; return selected;
} }
if (mode) if (mode)
{
// equal
if (min <= 1)
{ {
foreach (ClientCard card in cards) foreach (ClientCard card in cards)
{ {
//Logger.WriteLine("OpParam1 " + card.OpParam1 + " OpParam2 " + card.OpParam2 + " sum " + sum);
// try special level // try special level
if (card.OpParam2 == sum) if (card.OpParam2 == sum)
{ {
...@@ -394,48 +396,39 @@ namespace WindBot.Game ...@@ -394,48 +396,39 @@ namespace WindBot.Game
return new[] { card }; 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 IEnumerable<IEnumerable<ClientCard>> combos = CardContainer.GetCombinations(cards, i);
if (trysum + card.OpParam1 > sum)
foreach (IEnumerable<ClientCard> combo in combos)
{ {
continue; Logger.DebugWriteLine("--");
} int s1 = 0, s2 = 0;
selected.Add(card); selected = new List<ClientCard>();
trysum += card.OpParam1; foreach (ClientCard card in combo)
//Logger.DebugWriteLine(card.Id + "");
//Logger.DebugWriteLine(trysum + " selected " + sum);
if (trysum == sum)
{ {
return selected; s1 += card.OpParam1;
} s2 += (card.OpParam2 != 0) ? card.OpParam2 : card.OpParam1;
selected.Add(card);
} }
IList<ClientCard> selected2 = new List<ClientCard>(); if (s1 == sum || s2 == sum)
foreach (ClientCard card in selected)
{ {
// clone return selected;
selected2.Add(card);
} }
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 else
{
// larger
if (min <= 1)
{ {
foreach (ClientCard card in cards) foreach (ClientCard card in cards)
{ {
//Logger.WriteLine("OpParam1 " + card.OpParam1 + " OpParam2 " + card.OpParam2 + " sum " + sum);
// try special level // try special level
if (card.OpParam2 >= sum) if (card.OpParam2 >= sum)
{ {
...@@ -450,41 +443,35 @@ namespace WindBot.Game ...@@ -450,41 +443,35 @@ namespace WindBot.Game
return new[] { card }; 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>(); selected = new List<ClientCard>();
int trysum = 0; foreach (ClientCard card in combo)
foreach (ClientCard card in cards)
{ {
// try level add s1 += card.OpParam1;
s2 += (card.OpParam2 != 0) ? card.OpParam2 : card.OpParam1;
selected.Add(card); 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>(); if (s1 >= sum || s2 >= sum)
foreach (ClientCard card in selected)
{ {
// clone return selected;
selected2.Add(card);
} }
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> /// <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