Commit 5fd17c2f authored by mercury233's avatar mercury233

update SelectSum

parent f0072db2
...@@ -217,9 +217,11 @@ namespace MycardBot.Game.AI.Decks ...@@ -217,9 +217,11 @@ namespace MycardBot.Game.AI.Decks
return null; return null;
} }
public override IList<ClientCard> OnSelectSum(IList<ClientCard> cards, int sum, int min, int max) 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)
return null;
IList<ClientCard> avail = new List<ClientCard>(); IList<ClientCard> avail = new List<ClientCard>();
foreach (ClientCard card in cards) foreach (ClientCard card in cards)
{ {
......
...@@ -86,6 +86,7 @@ namespace WindBot.Game.AI.Decks ...@@ -86,6 +86,7 @@ namespace WindBot.Game.AI.Decks
AddExecutor(ExecutorType.Activate, (int)CardId.千手神, 千手神效果); AddExecutor(ExecutorType.Activate, (int)CardId.千手神, 千手神效果);
AddExecutor(ExecutorType.Activate, (int)CardId.万手神, 光枪龙之影灵衣); AddExecutor(ExecutorType.Activate, (int)CardId.万手神, 光枪龙之影灵衣);
AddExecutor(ExecutorType.Activate, (int)CardId.虹光之宣告者); AddExecutor(ExecutorType.Activate, (int)CardId.虹光之宣告者);
AddExecutor(ExecutorType.Activate, (int)CardId.影灵衣术士施里特);
AddExecutor(ExecutorType.SpSummon, (int)CardId.三叉龙之影灵衣); AddExecutor(ExecutorType.SpSummon, (int)CardId.三叉龙之影灵衣);
AddExecutor(ExecutorType.SpSummon, (int)CardId.决战兵器之影灵衣); AddExecutor(ExecutorType.SpSummon, (int)CardId.决战兵器之影灵衣);
...@@ -228,7 +229,7 @@ namespace WindBot.Game.AI.Decks ...@@ -228,7 +229,7 @@ namespace WindBot.Game.AI.Decks
AI.SelectCard((int)CardId.尤尼科之影灵衣); AI.SelectCard((int)CardId.尤尼科之影灵衣);
return true; return true;
} }
return false; return true;
} }
private bool 千手神效果() private bool 千手神效果()
...@@ -248,7 +249,7 @@ namespace WindBot.Game.AI.Decks ...@@ -248,7 +249,7 @@ namespace WindBot.Game.AI.Decks
AI.SelectCard((int)CardId.尤尼科之影灵衣); AI.SelectCard((int)CardId.尤尼科之影灵衣);
return true; return true;
} }
return false; return true;
} }
private bool 尤尼科之影灵衣() private bool 尤尼科之影灵衣()
......
...@@ -104,7 +104,7 @@ namespace WindBot.Game.AI ...@@ -104,7 +104,7 @@ namespace WindBot.Game.AI
return null; return null;
} }
public virtual IList<ClientCard> OnSelectSum(IList<ClientCard> cards, int sum, int min, int max) public virtual IList<ClientCard> OnSelectSum(IList<ClientCard> cards, int sum, int min, int max, bool mode)
{ {
return null; return null;
} }
......
...@@ -32,6 +32,8 @@ namespace WindBot.Game ...@@ -32,6 +32,8 @@ namespace WindBot.Game
public int Controller { get; private set; } public int Controller { get; private set; }
public int Disabled { get; private set; } public int Disabled { get; private set; }
public int SelectSeq { get; set; } public int SelectSeq { get; set; }
public int OpParam1 { get; set; }
public int OpParam2 { get; set; }
public bool CanDirectAttack { get; set; } public bool CanDirectAttack { get; set; }
public bool ShouldDirectAttack { get; set; } public bool ShouldDirectAttack { get; set; }
public bool Attacked { get; set; } public bool Attacked { get; set; }
......
...@@ -360,57 +360,122 @@ namespace WindBot.Game ...@@ -360,57 +360,122 @@ namespace WindBot.Game
/// <param name="sum">Result of the operation.</param> /// <param name="sum">Result of the operation.</param>
/// <param name="min">Minimum cards.</param> /// <param name="min">Minimum cards.</param>
/// <param name="max">Maximum cards.</param> /// <param name="max">Maximum cards.</param>
/// <param name="mode">True for equal.</param>
/// <returns></returns> /// <returns></returns>
public IList<ClientCard> OnSelectSum(IList<ClientCard> cards, int sum, int min, int max) public IList<ClientCard> OnSelectSum(IList<ClientCard> cards, int sum, int min, int max, bool mode)
{ {
IList<ClientCard> selected = new List<ClientCard>(); IList<ClientCard> selected = new List<ClientCard>();
selected = Executor.OnSelectSum(cards, sum, min, max); selected = Executor.OnSelectSum(cards, sum, min, max, mode);
if (selected != null) if (selected != null)
{ {
return selected; return selected;
} }
selected = new List<ClientCard>(); if (mode)
int trysum = 0;
foreach (ClientCard card in cards)
{ {
// try level add foreach (ClientCard card in cards)
if (trysum + card.Level > sum)
{ {
continue; //Logger.WriteLine("OpParam1 " + card.OpParam1 + " OpParam2 " + card.OpParam2 + " sum " + sum);
// try special level
if (card.OpParam2 == sum)
{
return new[] { card };
}
} }
selected.Add(card); foreach (ClientCard card in cards)
trysum += card.Level;
//Logger.DebugWriteLine(card.Id + "");
//Logger.DebugWriteLine(trysum + " selected " + sum);
if (trysum == sum)
{ {
return selected; // try level equal
if (card.OpParam1 == sum)
{
return new[] { card };
}
} }
} selected = new List<ClientCard>();
IList<ClientCard> selected2 = new List<ClientCard>(); int trysum = 0;
foreach (ClientCard card in selected) foreach (ClientCard card in cards)
{ {
// clone // try level add
selected2.Add(card); if (trysum + card.OpParam1 > sum)
} {
foreach (ClientCard card in selected) continue;
{ }
// try level sub selected.Add(card);
selected2.Remove(card); trysum += card.OpParam1;
trysum -= card.Level; //Logger.DebugWriteLine(card.Id + "");
//Logger.DebugWriteLine(card.Id + ""); //Logger.DebugWriteLine(trysum + " selected " + sum);
//Logger.DebugWriteLine(trysum + " selected2 " + sum); if (trysum == sum)
if (trysum == sum) {
return selected;
}
}
IList<ClientCard> selected2 = new List<ClientCard>();
foreach (ClientCard card in selected)
{ {
return selected2; // clone
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;
}
} }
} }
foreach (ClientCard card in cards) else
{ {
// try level equal foreach (ClientCard card in cards)
if (card.Level == sum) {
//Logger.WriteLine("OpParam1 " + card.OpParam1 + " OpParam2 " + card.OpParam2 + " sum " + sum);
// try special level
if (card.OpParam2 >= sum)
{
return new[] { card };
}
}
foreach (ClientCard card in cards)
{
// try level equal
if (card.OpParam1 >= sum)
{
return new[] { card };
}
}
selected = new List<ClientCard>();
int trysum = 0;
foreach (ClientCard card in cards)
{ {
return new[] { card }; // try level add
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)
{
// clone
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;
}
} }
} }
// try all // try all
......
...@@ -886,7 +886,7 @@ namespace WindBot.Game ...@@ -886,7 +886,7 @@ namespace WindBot.Game
private void OnSelectSum(BinaryReader packet) private void OnSelectSum(BinaryReader packet)
{ {
packet.ReadByte(); // mode bool mode = packet.ReadByte() == 0;
packet.ReadByte(); // player packet.ReadByte(); // player
int sumval = packet.ReadInt32(); int sumval = packet.ReadInt32();
int min = packet.ReadByte(); int min = packet.ReadByte();
...@@ -905,26 +905,35 @@ namespace WindBot.Game ...@@ -905,26 +905,35 @@ namespace WindBot.Game
CardLocation loc = (CardLocation)packet.ReadByte(); CardLocation loc = (CardLocation)packet.ReadByte();
int seq = packet.ReadByte(); int seq = packet.ReadByte();
ClientCard card = _duel.GetCard(player, loc, seq); ClientCard card = _duel.GetCard(player, loc, seq);
if (card != null) if (cardId != 0 && card.Id != cardId)
card.SetId(cardId);
card.SelectSeq = i;
int OpParam = packet.ReadInt32();
int OpParam1 = OpParam & 0xffff;
int OpParam2 = OpParam >> 16;
if (OpParam2 > 0 && OpParam1 > OpParam2)
{ {
if (cardId != 0 && card.Id != cardId) card.OpParam1 = OpParam2;
card.SetId(cardId); card.OpParam2 = OpParam1;
card.SelectSeq = i; }
else
{
card.OpParam1 = OpParam1;
card.OpParam2 = OpParam2;
} }
if (j == 0) if (j == 0)
mandatoryCards.Add(card); mandatoryCards.Add(card);
else else
cards.Add(card); cards.Add(card);
packet.ReadInt32();
} }
} }
for (int k = 0; k < mandatoryCards.Count; ++k) for (int k = 0; k < mandatoryCards.Count; ++k)
{ {
sumval -= mandatoryCards[k].Level; sumval -= mandatoryCards[k].OpParam1;
} }
IList<ClientCard> selected = _ai.OnSelectSum(cards, sumval, min, max); IList<ClientCard> selected = _ai.OnSelectSum(cards, sumval, min, max, mode);
byte[] result = new byte[mandatoryCards.Count + selected.Count + 1]; byte[] result = new byte[mandatoryCards.Count + selected.Count + 1];
int index = 0; int index = 0;
......
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