Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix executors #175

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 49 additions & 12 deletions Game/AI/Decks/AltergeistExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using WindBot;
using WindBot.Game;
using WindBot.Game.AI;
using System.Linq;

namespace WindBot.Game.AI.Decks
{
Expand Down Expand Up @@ -324,23 +325,37 @@ public int GetTotalATK(IList<ClientCard> list)

public int SelectSTPlace(ClientCard card=null, bool avoid_Impermanence = false)
{
List<int> list = new List<int> { 0, 1, 2, 3, 4 };
if (card == null) card = Card;
List<int> list = new List<int>();
for (int seq = 0; seq < 5; ++seq)
{
if (Bot.SpellZone[seq] == null)
{
if (card != null && card.Location == CardLocation.Hand && avoid_Impermanence && Impermanence_list.Contains(seq)) continue;
list.Add(seq);
}
}
int n = list.Count;
while (n-- > 1)
{
int index = Program.Rand.Next(n + 1);
int temp = list[index];
list[index] = list[n];
list[n] = temp;
int index = Program.Rand.Next(list.Count);
int nextIndex = (index + Program.Rand.Next(list.Count - 1)) % list.Count;
int tempInt = list[index];
list[index] = list[nextIndex];
list[nextIndex] = tempInt;
}
foreach (int seq in list)
if (avoid_Impermanence && Bot.GetMonsters().Any(c => c.IsFaceup() && !c.IsDisabled()))
{
int zone = (int)System.Math.Pow(2, seq);
if (Bot.SpellZone[seq] == null)
foreach (int seq in list)
{
if (card != null && card.Location == CardLocation.Hand && avoid_Impermanence && Impermanence_list.Contains(seq)) continue;
return zone;
};
ClientCard enemySpell = Enemy.SpellZone[4 - seq];
if (enemySpell != null && enemySpell.IsFacedown()) continue;
return (int)System.Math.Pow(2, seq);
}
}
foreach (int seq in list)
{
return (int)System.Math.Pow(2, seq);
}
return 0;
}
Expand Down Expand Up @@ -2656,6 +2671,27 @@ public override void OnNewTurn()
attacked_Meluseek.Clear();
}

public override void OnChaining(int player, ClientCard card)
{
if (card == null) return;

if (player == 1)
{
if (card.IsCode(_CardId.InfiniteImpermanence))
{
for (int i = 0; i < 5; ++i)
{
if (Enemy.SpellZone[i] == card)
{
Impermanence_list.Add(4-i);
break;
}
}
}
}
base.OnChaining(player, card);
}

public bool MonsterRepos()
{
if (Card.Attack == 0) return (Card.IsAttack());
Expand Down Expand Up @@ -2797,7 +2833,8 @@ public override IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min,
// throw all??
return null;
}
return null;

return base.OnSelectCard(cards, min, max, hint, cancelable);
}

public override CardPosition OnSelectPosition(int cardId, IList<CardPosition> positions)
Expand Down
3 changes: 2 additions & 1 deletion Game/AI/Decks/BlueEyesExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ public override IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min,
return Util.CheckSelectCount(result, cards, min, max);
}
Logger.DebugWriteLine("Use default.");
return null;

return base.OnSelectCard(cards, min, max, hint, cancelable);
}

public override IList<ClientCard> OnSelectXyzMaterial(IList<ClientCard> cards, int min, int max)
Expand Down
15 changes: 8 additions & 7 deletions Game/AI/Decks/DogmatikaExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System;
using System.CodeDom;
using System.Security.AccessControl;

namespace WindBot.Game.AI.Decks
{
Expand Down Expand Up @@ -1098,8 +1096,8 @@ public override void OnMove(int cardId, int previousControler, int previousLocat

public override ClientCard OnSelectAttacker(IList<ClientCard> attackers, IList<ClientCard> defenders)
{
if (attackers.Count() > 0) return attackers[attackers.Count() - 1];
return null;
if (attackers.Count() > 0) return attackers.OrderBy(card => card.Attack).FirstOrDefault();
return base.OnSelectAttacker(attackers, defenders);
}

public override BattlePhaseAction OnSelectAttackTarget(ClientCard attacker, IList<ClientCard> defenders)
Expand All @@ -1113,6 +1111,9 @@ public override BattlePhaseAction OnSelectAttackTarget(ClientCard attacker, ILis

if (attacker.RealPower > defender.RealPower)
return AI.Attack(attacker, defender);

if (attacker.RealPower == defender.RealPower && defender.IsAttack() && Bot.GetMonsterCount() >= Enemy.GetMonsterCount())
return AI.Attack(attacker, defender);
}

if (attacker.CanDirectAttack)
Expand Down Expand Up @@ -2031,7 +2032,7 @@ public bool SinfulSpoilsOfDoom_RcielaActivate()
}

// decrease attack
if (Bot.UnderAttack && !onlyAlbaZoa && (Bot.BattlingMonster?.GetDefensePower() ?? 0) <= (Enemy.BattlingMonster?.GetDefensePower() ?? 0))
if (Bot.UnderAttack && !onlyAlbaZoa && (Bot.BattlingMonster?.GetDefensePower() ?? 0) <= (Enemy.BattlingMonster?.GetDefensePower() ?? 0) && Duel.LastChainPlayer != 0)
{
activateFlag = true;
}
Expand Down Expand Up @@ -2425,7 +2426,7 @@ public bool DogmatikaPunishmentActivate()
if (targetCard == null || extraToDiscard == null)
{
bool check1 = DefaultOnBecomeTarget();
bool check2 = Bot.UnderAttack && (Bot.BattlingMonster?.GetDefensePower() ?? 0) <= (Enemy.BattlingMonster?.GetDefensePower() ?? 0);
bool check2 = Bot.UnderAttack && (Bot.BattlingMonster?.GetDefensePower() ?? 0) <= (Enemy.BattlingMonster?.GetDefensePower() ?? 0) && Duel.LastChainPlayer != 0;;
bool check3 = Duel.Player == 1 && Duel.Phase == DuelPhase.End && Duel.LastChainPlayer != 0;
bool check4 = Duel.Player == 1 && avoid2Monster && Enemy.GetMonsterCount() >= 2 && Duel.LastChainPlayer != 0;
Logger.DebugWriteLine("===punishment check flag: " + check1 + " " + check2 + " " + check3 + " " + check4);
Expand Down Expand Up @@ -2820,7 +2821,7 @@ public bool MonsterRepos()

if (Card.IsAttack() && enemyBetter)
return true;
if (Card.IsDefense() && !enemyBetter && selfAttack >= Card.Defense)
if (Card.IsDefense() && !enemyBetter)
return true;
return false;
}
Expand Down
40 changes: 29 additions & 11 deletions Game/AI/Decks/ExosisterExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -629,25 +629,42 @@ public bool CheckWhetherNegated(bool disablecheck = true){
/// <param name="avoidList">Whether need to avoid set in this place</param>
public void SelectSTPlace(ClientCard card = null, bool avoidImpermanence = false, List<int> avoidList = null)
{
List<int> list = new List<int> { 0, 1, 2, 3, 4 };
if (card == null) card = Card;
List<int> list = new List<int>();
for (int seq = 0; seq < 5; ++seq)
{
if (Bot.SpellZone[seq] == null)
{
if (card != null && card.Location == CardLocation.Hand && avoidImpermanence && infiniteImpermanenceList.Contains(seq)) continue;
if (avoidList != null && avoidList.Contains(seq)) continue;
list.Add(seq);
}
}
int n = list.Count;
while (n-- > 1)
{
int index = Program.Rand.Next(n + 1);
int temp = list[index];
list[index] = list[n];
list[n] = temp;
int index = Program.Rand.Next(list.Count);
int nextIndex = (index + Program.Rand.Next(list.Count - 1)) % list.Count;
int tempInt = list[index];
list[index] = list[nextIndex];
list[nextIndex] = tempInt;
}
foreach (int seq in list)
if (avoidImpermanence && Bot.GetMonsters().Any(c => c.IsFaceup() && !c.IsDisabled()))
{
int zone = (int)System.Math.Pow(2, seq);
if (Bot.SpellZone[seq] == null)
foreach (int seq in list)
{
if (card != null && card.Location == CardLocation.Hand && avoidImpermanence && infiniteImpermanenceList.Contains(seq)) continue;
if (avoidList != null && avoidList.Contains(seq)) continue;
ClientCard enemySpell = Enemy.SpellZone[4 - seq];
if (enemySpell != null && enemySpell.IsFacedown()) continue;
int zone = (int)System.Math.Pow(2, seq);
AI.SelectPlace(zone);
return;
};
}
}
foreach (int seq in list)
{
int zone = (int)System.Math.Pow(2, seq);
AI.SelectPlace(zone);
return;
}
AI.SelectPlace(0);
}
Expand Down Expand Up @@ -816,6 +833,7 @@ public override void OnChainEnd()

public override void OnNewTurn()
{
if (Duel.Turn <= 1) calledbytheGraveCount.Clear();
enemyActivateMaxxC = false;
enemyActivateLockBird = false;
infiniteImpermanenceList.Clear();
Expand Down
31 changes: 24 additions & 7 deletions Game/AI/Decks/SwordsoulExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ public override IList<ClientCard> OnSelectCard(IList<ClientCard> cards, int min,

public override void OnNewTurn()
{
if (Duel.Turn <= 1) calledbytheGraveCount.Clear();
enemyActivateMaxxC = false;
enemyActivateLockBird = false;

Expand Down Expand Up @@ -780,7 +781,17 @@ public override void OnChainEnd()
/// <param name="avoidList">Whether need to avoid set in this place</param>
public void SelectSTPlace(ClientCard card = null, bool avoidImpermanence = false, List<int> avoidList = null)
{
List<int> list = new List<int> { 0, 1, 2, 3, 4 };
if (card == null) card = Card;
List<int> list = new List<int>();
for (int seq = 0; seq < 5; ++seq)
{
if (Bot.SpellZone[seq] == null)
{
if (card != null && card.Location == CardLocation.Hand && avoidImpermanence && infiniteImpermanenceList.Contains(seq)) continue;
if (avoidList != null && avoidList.Contains(seq)) continue;
list.Add(seq);
}
}
int n = list.Count;
while (n-- > 1)
{
Expand All @@ -790,16 +801,22 @@ public void SelectSTPlace(ClientCard card = null, bool avoidImpermanence = false
list[index] = list[nextIndex];
list[nextIndex] = tempInt;
}
foreach (int seq in list)
if (avoidImpermanence && Bot.GetMonsters().Any(c => c.IsFaceup() && !c.IsDisabled()))
{
int zone = (int)System.Math.Pow(2, seq);
if (Bot.SpellZone[seq] == null)
foreach (int seq in list)
{
if (card != null && card.Location == CardLocation.Hand && avoidImpermanence && infiniteImpermanenceList.Contains(seq)) continue;
if (avoidList != null && avoidList.Contains(seq)) continue;
ClientCard enemySpell = Enemy.SpellZone[4 - seq];
if (enemySpell != null && enemySpell.IsFacedown()) continue;
int zone = (int)System.Math.Pow(2, seq);
AI.SelectPlace(zone);
return;
};
}
}
foreach (int seq in list)
{
int zone = (int)System.Math.Pow(2, seq);
AI.SelectPlace(zone);
return;
}
AI.SelectPlace(0);
}
Expand Down
Loading