Commit 5fd17c2f authored by mercury233's avatar mercury233

update SelectSum

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