Commit c81e590f authored by mercury233's avatar mercury233

add GetLinkedZones and GetBotAvailZonesFromExtraDeck

parent 47f5ca86
......@@ -265,6 +265,64 @@ namespace WindBot.Game.AI
return Duel.Turn == 1 || Duel.Phase == DuelPhase.Main2;
}
internal bool inListOrNull(ClientCard card, IList<ClientCard> list)
{
return card == null || list.Contains(card);
}
public int GetBotAvailZonesFromExtraDeck(IList<ClientCard> remove)
{
if (!Duel.IsNewRule)
return Zones.MainMonsterZones;
int result = 0;
if (inListOrNull(Bot.MonsterZone[5], remove) && inListOrNull(Bot.MonsterZone[6], remove) &&
(inListOrNull(Enemy.MonsterZone[5], remove) || inListOrNull(Enemy.MonsterZone[6], remove)))
result |= Zones.ExtraMonsterZones;
if (inListOrNull(Bot.MonsterZone[0], remove) &&
(!inListOrNull(Bot.MonsterZone[1], remove) && Bot.MonsterZone[1].HasLinkMarker(CardLinkMarker.Left) ||
!inListOrNull(Bot.MonsterZone[5], remove) && Bot.MonsterZone[5].HasLinkMarker(CardLinkMarker.BottomLeft) ||
!inListOrNull(Enemy.MonsterZone[6], remove) && Enemy.MonsterZone[6].HasLinkMarker(CardLinkMarker.TopRight)))
result += Zones.z0;
if (inListOrNull(Bot.MonsterZone[1], remove) &&
(!inListOrNull(Bot.MonsterZone[0], remove) && Bot.MonsterZone[0].HasLinkMarker(CardLinkMarker.Right) ||
!inListOrNull(Bot.MonsterZone[2], remove) && Bot.MonsterZone[2].HasLinkMarker(CardLinkMarker.Left) ||
!inListOrNull(Bot.MonsterZone[5], remove) && Bot.MonsterZone[5].HasLinkMarker(CardLinkMarker.Bottom) ||
!inListOrNull(Enemy.MonsterZone[6], remove) && Enemy.MonsterZone[6].HasLinkMarker(CardLinkMarker.Top)))
result += Zones.z1;
if (inListOrNull(Bot.MonsterZone[2], remove) &&
(!inListOrNull(Bot.MonsterZone[1], remove) && Bot.MonsterZone[1].HasLinkMarker(CardLinkMarker.Right) ||
!inListOrNull(Bot.MonsterZone[3], remove) && Bot.MonsterZone[3].HasLinkMarker(CardLinkMarker.Left) ||
!inListOrNull(Bot.MonsterZone[5], remove) && Bot.MonsterZone[5].HasLinkMarker(CardLinkMarker.BottomRight) ||
!inListOrNull(Enemy.MonsterZone[6], remove) && Enemy.MonsterZone[6].HasLinkMarker(CardLinkMarker.TopLeft) ||
!inListOrNull(Bot.MonsterZone[6], remove) && Bot.MonsterZone[6].HasLinkMarker(CardLinkMarker.BottomLeft) ||
!inListOrNull(Enemy.MonsterZone[5], remove) && Enemy.MonsterZone[5].HasLinkMarker(CardLinkMarker.TopRight)))
result += Zones.z2;
if (inListOrNull(Bot.MonsterZone[3], remove) &&
(!inListOrNull(Bot.MonsterZone[2], remove) && Bot.MonsterZone[2].HasLinkMarker(CardLinkMarker.Right) ||
!inListOrNull(Bot.MonsterZone[4], remove) && Bot.MonsterZone[4].HasLinkMarker(CardLinkMarker.Left) ||
!inListOrNull(Bot.MonsterZone[6], remove) && Bot.MonsterZone[6].HasLinkMarker(CardLinkMarker.Bottom) ||
!inListOrNull(Enemy.MonsterZone[5], remove) && Enemy.MonsterZone[5].HasLinkMarker(CardLinkMarker.Top)))
result += Zones.z3;
if (inListOrNull(Bot.MonsterZone[4], remove) &&
(!inListOrNull(Bot.MonsterZone[3], remove) && Bot.MonsterZone[3].HasLinkMarker(CardLinkMarker.Right) ||
!inListOrNull(Bot.MonsterZone[6], remove) && Bot.MonsterZone[6].HasLinkMarker(CardLinkMarker.BottomRight) ||
!inListOrNull(Enemy.MonsterZone[5], remove) && Enemy.MonsterZone[5].HasLinkMarker(CardLinkMarker.TopLeft)))
result += Zones.z4;
return result;
}
public int GetBotAvailZonesFromExtraDeck(ClientCard remove)
{
return GetBotAvailZonesFromExtraDeck(new [] { remove });
}
public int GetBotAvailZonesFromExtraDeck()
{
return GetBotAvailZonesFromExtraDeck(new List<ClientCard>());
}
public bool IsChainTarget(ClientCard card)
{
return Duel.ChainTargets.Any(card.Equals);
......
......@@ -2161,7 +2161,7 @@ namespace WindBot.Game.AI.Decks
if (Duel.Phase != DuelPhase.Main2) return false;
ClientCard card_ex_left = Enemy.MonsterZone[6];
ClientCard card_ex_right = Enemy.MonsterZone[5];
if (card_ex_left != null && card_ex_left.HasLinkMarker((int)LinkMarker.Top))
if (card_ex_left != null && card_ex_left.HasLinkMarker((int)CardLinkMarker.Top))
{
ClientCard self_card_1 = Bot.MonsterZone[1];
if (self_card_1 == null)
......@@ -2178,7 +2178,7 @@ namespace WindBot.Game.AI.Decks
return true;
}
}
if (card_ex_right != null && card_ex_right.HasLinkMarker((int)LinkMarker.Top))
if (card_ex_right != null && card_ex_right.HasLinkMarker((int)CardLinkMarker.Top))
{
ClientCard self_card_2 = Bot.MonsterZone[3];
if (self_card_2 == null)
......
......@@ -154,11 +154,61 @@ namespace WindBot.Game
return (LinkMarker & dir) != 0;
}
public bool HasLinkMarker(LinkMarker dir)
public bool HasLinkMarker(CardLinkMarker dir)
{
return (LinkMarker & (int)dir) != 0;
}
public int GetLinkedZones()
{
if (!HasType(CardType.Link) || Location != CardLocation.MonsterZone)
return 0;
int zones = 0;
if (Sequence > 0 && Sequence <= 4 && HasLinkMarker(CardLinkMarker.Left))
zones |= 1 << (Sequence - 1);
if (Sequence <= 3 && HasLinkMarker(CardLinkMarker.Right))
zones |= 1 << (Sequence + 1);
if (Sequence == 0 && HasLinkMarker(CardLinkMarker.TopRight)
|| Sequence == 1 && HasLinkMarker(CardLinkMarker.Top)
|| Sequence == 2 && HasLinkMarker(CardLinkMarker.TopLeft))
zones |= (1 << 5) | (1 << (16 + 6));
if (Sequence == 2 && HasLinkMarker(CardLinkMarker.TopRight)
|| Sequence == 3 && HasLinkMarker(CardLinkMarker.Top)
|| Sequence == 4 && HasLinkMarker(CardLinkMarker.TopLeft))
zones |= (1 << 6) | (1 << (16 + 5));
if (Sequence == 5)
{
if (HasLinkMarker(CardLinkMarker.BottomLeft))
zones |= 1 << 0;
if (HasLinkMarker(CardLinkMarker.Bottom))
zones |= 1 << 1;
if (HasLinkMarker(CardLinkMarker.BottomRight))
zones |= 1 << 2;
if (HasLinkMarker(CardLinkMarker.TopLeft))
zones |= 1 << (16 + 4);
if (HasLinkMarker(CardLinkMarker.Top))
zones |= 1 << (16 + 3);
if (HasLinkMarker(CardLinkMarker.TopRight))
zones |= 1 << (16 + 2);
}
if (Sequence == 6)
{
if (HasLinkMarker(CardLinkMarker.BottomLeft))
zones |= 1 << 2;
if (HasLinkMarker(CardLinkMarker.Bottom))
zones |= 1 << 3;
if (HasLinkMarker(CardLinkMarker.BottomRight))
zones |= 1 << 4;
if (HasLinkMarker(CardLinkMarker.TopLeft))
zones |= 1 << (16 + 2);
if (HasLinkMarker(CardLinkMarker.Top))
zones |= 1 << (16 + 1);
if (HasLinkMarker(CardLinkMarker.TopRight))
zones |= 1 << (16 + 0);
}
return zones;
}
public bool HasType(CardType type)
{
return (Type & (int)type) != 0;
......
......@@ -97,7 +97,6 @@ namespace WindBot.Game
return count;
}
public int GetFieldCount()
{
return GetSpellCount() + GetMonsterCount();
......@@ -113,6 +112,16 @@ namespace WindBot.Game
return GetMonsters().Count == 0 && GetSpells().Count == 0;
}
public int GetLinkedZones()
{
int zones = 0;
for (int i = 0; i < 7; i++)
{
zones |= MonsterZone[i]?.GetLinkedZones() ?? 0;
}
return zones;
}
public List<ClientCard> GetMonsters()
{
return GetCards(MonsterZone);
......
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