Skip to content

Commit

Permalink
AI_Labrynth (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wind2009-Louse authored Jan 11, 2024
1 parent eec2779 commit 6d4d8bb
Show file tree
Hide file tree
Showing 12 changed files with 4,505 additions and 13 deletions.
5 changes: 5 additions & 0 deletions BotWrapper/bot.conf
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ Name=尼亚 Deck=Altergeist Dialog=near.zh-CN
幻变骚灵卡组。
AI_LV3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020

!尼亚-拉比林斯迷宫
Name=尼亚 Deck=Labrynth Dialog=near.zh-CN
拉比林斯迷宫卡组。
AI_LV3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020

!复制梁龙-闪刀姬
Name=复制梁龙 Deck=SkyStriker Dialog=anothercopy.zh-CN
旧式闪刀姬卡组。
Expand Down
59 changes: 59 additions & 0 deletions Decks/AI_Labrynth.ydk
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#created by ...
#main
81497285
81497285
2347656
41165831
73602965
73602965
75730490
1225009
1225009
1225009
37629703
37629703
37629703
14558127
14558127
14558127
23434538
23434538
23434538
74018812
74018812
74018812
2511
2511
2511
49238328
49238328
5380979
5380979
6351147
6351147
10045474
10045474
10045474
30748475
53417695
83326048
92714517
92714517
92714517
#extra
22850702
22850702
93039339
93039339
29479265
93084621
93084621
24269961
24269961
24269961
67680512
67680512
29301450
71607202
94259633
!side
4 changes: 2 additions & 2 deletions Game/AI/Decks/DogmatikaExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ public override void OnNewTurn()
}
}

public override void OnMove(int cardId, int previousControler, int previousLocation, int currentControler, int currentLocation)
public override void OnMove(ClientCard card, int previousControler, int previousLocation, int currentControler, int currentLocation)
{
if (previousControler == 1 && currentLocation == (int)CardLocation.MonsterZone)
{
Expand All @@ -1093,7 +1093,7 @@ public override void OnMove(int cardId, int previousControler, int previousLocat
}
}

base.OnMove(cardId, previousControler, previousLocation, currentControler, currentLocation);
base.OnMove(card, previousControler, previousLocation, currentControler, currentLocation);
}

public override BattlePhaseAction OnBattle(IList<ClientCard> attackers, IList<ClientCard> defenders)
Expand Down
4,368 changes: 4,368 additions & 0 deletions Game/AI/Decks/LabrynthExecutor.cs

Large diffs are not rendered by default.

39 changes: 33 additions & 6 deletions Game/AI/DefaultExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ protected class _CardId
public const int VaylantzWorld_ShinraBansho = 49568943;
public const int VaylantzWorld_KonigWissen = 75952542;
public const int DivineArsenalAAZEUS_SkyThunder = 90448279;
public const int LightningStorm = 14532163;

public const int BelialMarquisOfDarkness = 33655493;
public const int ChirubiméPrincessOfAutumnLeaves = 87294988;
Expand Down Expand Up @@ -223,6 +224,8 @@ protected DefaultExecutor(GameAI ai, Duel duel)
AddExecutor(ExecutorType.Activate, _CardId.SantaClaws);
}

protected int lightningStormOption = -1;

/// <summary>
/// Defined:
/// if monster with code as KEY, other monsters with rules as VALUE won't be targeted for attack.
Expand Down Expand Up @@ -395,6 +398,9 @@ public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender
}
}

if (attacker.EquipCards.Any(equip => equip.IsCode(_CardId.MoonMirrorShield) && !equip.IsDisabled()))
attacker.RealPower = defender.RealPower + 100;

if (!defender.IsDisabled())
{
Func<ClientCard, List<ClientCard>, bool> defenderRule = (card, monsterList) => false;
Expand Down Expand Up @@ -430,6 +436,9 @@ public override bool OnPreBattleBetween(ClientCard attacker, ClientCard defender

if (Enemy.HasInSpellZone(_CardId.CrusadiaVanguard, true) && Enemy.GetMonsters().Any(card => card.HasSetcode(_Setcode.Crusadia) && card.HasType(CardType.Link)) && !defender.HasType(CardType.Link))
return false;

if (defender.IsCode(_CardId.RescueACEHydrant) && !defender.IsDisabled() && Enemy.GetMonsters().Any(monster => monster.HasSetcode(_Setcode.RescueACE) && !monster.IsCode(_CardId.RescueACEHydrant)))
return false;

if (Enemy.HasInSpellZone(_CardId.SilenforcingBarrier, true) && Enemy.HasInMonstersZone(_CardId.NovoxTheSilenforcerDisciple, faceUp: true) && !defender.HasType(CardType.Ritual))
return false;
Expand Down Expand Up @@ -1025,6 +1034,8 @@ protected bool DefaultOnBecomeTarget()

if (Util.ChainContainsCard(destroyAllList)) return true;
if (Enemy.HasInSpellZone(destroyAllOpponentSpellList, true) && Card.Location == CardLocation.SpellZone) return true;
if (lightningStormOption == 0 && Card.Location == CardLocation.MonsterZone && Card.IsAttack()) return true;
if (lightningStormOption == 1 && Card.Location == CardLocation.SpellZone) return true;
// TODO: ChainContainsCard(id, player)
return false;
}
Expand Down Expand Up @@ -1120,12 +1131,11 @@ protected bool DefaultDimensionalBarrier()
bool nontuner = false;
foreach (ClientCard monster in monsters)
{
if (monster.HasType(CardType.Tuner))
tuner = true;
else if (!monster.HasType(CardType.Xyz) && !monster.HasType(CardType.Link))
if (!monster.HasType(CardType.Xyz | CardType.Link))
{
nontuner = true;
levels[monster.Level] = levels[monster.Level] + 1;
if (monster.HasType(CardType.Tuner)) tuner = true;
else nontuner = true;
if (!monster.HasType(CardType.Token)) levels[monster.Level] = levels[monster.Level] + 1;
}

if (monster.IsOneForXyz())
Expand Down Expand Up @@ -1156,7 +1166,8 @@ protected bool DefaultDimensionalBarrier()
}
}
ClientCard lastchaincard = Util.GetLastChainCard();
if (Duel.LastChainPlayer == 1 && lastchaincard != null && !lastchaincard.IsDisabled())
if (Duel.LastChainPlayer == 1 && lastchaincard != null && !lastchaincard.IsDisabled()
&& (lastchaincard.HasType(CardType.Spell | CardType.Trap) || lastchaincard.Location == CardLocation.MonsterZone))
{
if (lastchaincard.HasType(CardType.Ritual))
{
Expand Down Expand Up @@ -1454,5 +1465,21 @@ protected bool DefaultVaylantzWorld_KonigWissen()

return false;
}

public override void OnReceivingAnnouce(int player, int data)
{
if (player == 1 && data == Util.GetStringId(_CardId.LightningStorm, 0) || data == Util.GetStringId(_CardId.LightningStorm, 1))
{
lightningStormOption = data - Util.GetStringId(_CardId.LightningStorm, 0);
}

base.OnReceivingAnnouce(player, data);
}

public override void OnChainEnd()
{
lightningStormOption = -1;
base.OnChainEnd();
}
}
}
1 change: 1 addition & 0 deletions Game/AI/Enums/Floodgate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public enum Floodgate
ElShaddollConstruct = 20366274,
ElShaddollGrysra = 48424886,
ElShaddollWinda = 94977269,
HotRedDragonArchfiendAbyss = 9753964,
UltimateConductorTytanno = 18940556,
OvertexCoatls = 41782653,
FirePrison = 269510,
Expand Down
1 change: 1 addition & 0 deletions Game/AI/Enums/FusionSpell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public enum FusionSpell
FaceCardFusion = 29062925,
MyutantFusion = 42577802,
MyutantCry = 31855260,
FallenOfAlbaz = 68468459,
GreaterPolymerization = 7614732,
UltimateFusion = 71143015,
BrandedFusion = 44362883,
Expand Down
8 changes: 7 additions & 1 deletion Game/AI/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public virtual void OnChainEnd()
{
// For overriding
}

public virtual void OnReceivingAnnouce(int player, int data)
{
// For overriding
}

public virtual void OnNewPhase()
{
// Some AI need do something on new phase
Expand All @@ -118,7 +124,7 @@ public virtual void OnDraw(int player)
// Some AI need do something on draw
}

public virtual void OnMove(int cardId, int previousControler, int previousLocation, int currentControler, int currentLocation)
public virtual void OnMove(ClientCard card, int previousControler, int previousLocation, int currentControler, int currentLocation)
{
// Some AI need do something on card's moving
}
Expand Down
7 changes: 6 additions & 1 deletion Game/AI/HintMsg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public static class HintMsg
ToZone = 571,
Counter = 572,
Disable = 573,
OperateCard = 574;
OperateCard = 574,
RITUAL = 1057,
FUSION = 1056,
SYNCHRO = 1063,
XYZ = 1073,
PENDULUM = 1074;
}
}
14 changes: 12 additions & 2 deletions Game/GameAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ public void OnNewPhase()
Executor.OnNewPhase();
}

public void OnMove(int cardId, int previousControler, int previousLocation, int currentControler, int currentLocation)
public void OnMove(ClientCard card, int previousControler, int previousLocation, int currentControler, int currentLocation)
{
Executor.OnMove(cardId, previousControler, previousLocation, currentControler, currentLocation);
Executor.OnMove(card, previousControler, previousLocation, currentControler, currentLocation);
}

/// <summary>
Expand Down Expand Up @@ -157,6 +157,16 @@ public void OnChainEnd()
Executor.OnChainEnd();
}

/// <summary>
/// Called when receiving annouce
/// </summary>
/// <param name="player">Player who announce.</param>
/// <param name="data">Annouced info.</param>
public void OnReceivingAnnouce(int player, int data)
{
Executor.OnReceivingAnnouce(player, data);
}

/// <summary>
/// Called when the AI has to do something during the battle phase.
/// </summary>
Expand Down
11 changes: 10 additions & 1 deletion Game/GameBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,22 @@ private void OnHint(BinaryReader packet)
{
_select_hint = data;
}
if (type == 4) // HINT_OPSELECTED
{
_ai.OnReceivingAnnouce(player, data);
}
}

private void OnStart(BinaryReader packet)
{
int type = packet.ReadByte();
_duel.IsFirst = (type & 0xF) == 0;
_duel.Turn = 0;
_duel.LastChainLocation = 0;
_duel.LastChainPlayer = -1;
_duel.LastChainTargets.Clear();
_duel.LastSummonedCards.Clear();
_duel.LastSummonPlayer = -1;
int duel_rule = packet.ReadByte();
_ai.Duel.IsNewRule = (duel_rule >= 4);
_ai.Duel.IsNewRule2020 = (duel_rule >= 5);
Expand Down Expand Up @@ -653,7 +662,7 @@ private void OnMove(BinaryReader packet)
}
}

_ai.OnMove(cardId, previousControler, previousLocation, currentControler, currentLocation);
_ai.OnMove(card, previousControler, previousLocation, currentControler, currentLocation);
}

private void OnSwap(BinaryReader packet)
Expand Down
1 change: 1 addition & 0 deletions WindBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<Compile Include="Game\AI\Decks\GraydleExecutor.cs" />
<Compile Include="Game\AI\Decks\GrenMajuThunderBoarderExecutor.cs" />
<Compile Include="Game\AI\Decks\LightswornExecutor.cs" />
<Compile Include="Game\AI\Decks\LabrynthExecutor.cs" />
<Compile Include="Game\AI\Decks\LightswornShaddoldinosourExecutor.cs" />
<Compile Include="Game\AI\Decks\PhantasmExecutor.cs" />
<Compile Include="Game\AI\Decks\QliphortExecutor.cs" />
Expand Down

0 comments on commit 6d4d8bb

Please sign in to comment.