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

add smart selectplace #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
315 changes: 315 additions & 0 deletions Game/AI/DefaultExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,196 @@ protected class _CardId
public const int ImperialOrder = 61740673;
public const int NaturiaBeast = 33198837;
public const int AntiSpellFragrance = 58921041;

public const int JackKnightOfTheLavenderDust = 28692962;
public const int JackKnightOfTheCobaltDepths = 92204263;
public const int JackKnightOfTheCrimsonLotus = 56809158;
public const int JackKnightOfTheGoldenBlossom = 29415459;
public const int JackKnightOfTheVerdantGale = 66022706;
public const int JackKnightOfTheAmberShade = 93020401;
public const int JackKnightOfTheAzureSky = 20537097;
public const int MekkKnightMorningStar = 72006609;
public const int JackKnightOfTheWorldScar = 38502358;
public const int WhisperOfTheWorldLegacy = 62530723;
public const int TrueDepthsOfTheWorldLegacy = 98935722;
public const int KeyToTheWorldLegacy = 2930675;
}

public int ReverseBotEnemyZone(int zone = -1)
{
if (zone == 0)
return 4;
if (zone == 1)
return 3;
if (zone == 2)
return 2;
if (zone == 3)
return 1;
if (zone == 4)
return 0;
if (zone == 5)
return 6;
if (zone == 6)
return 5;
return -1;
}

public int GetReverseColumnMainZone(int zone = -1)
{
if (zone == 0)
return 4;
if (zone == 1 || zone == 5)
return 3;
if (zone == 2)
return 2;
if (zone == 3 || zone == 6)
return 3;
if (zone == 4)
return 0;
return -1;
}

public int ReverseZone16bitTo32bit(int zone = -1)
{
if (zone == Zones.z0)
return 0;
if (zone == Zones.z1)
return 1;
if (zone == Zones.z2)
return 2;
if (zone == Zones.z3)
return 3;
if (zone == Zones.z4)
return 4;
if (zone == Zones.z5)
return 5;
if (zone == Zones.z6)
return 6;
return -1;
}

public int ReverseZoneTo16bit(int zone = -1)
{
if (zone == 0)
return Zones.z0;
if (zone == 1)
return Zones.z1;
if (zone == 2)
return Zones.z2;
if (zone == 3)
return Zones.z3;
if (zone == 4)
return Zones.z4;
if (zone == 5)
return Zones.z5;
if (zone == 6)
return Zones.z6;
return -1;
}

public bool IsJackKnightMonster(int enemyzone)
{
if (enemyzone == -1)
return false;
if (Enemy.MonsterZone[enemyzone] == null)
return false;
if (Enemy.MonsterZone[enemyzone].Id != _CardId.JackKnightOfTheAmberShade &&
Enemy.MonsterZone[enemyzone].Id != _CardId.JackKnightOfTheAzureSky &&
Enemy.MonsterZone[enemyzone].Id != _CardId.JackKnightOfTheCobaltDepths &&
Enemy.MonsterZone[enemyzone].Id != _CardId.JackKnightOfTheCrimsonLotus &&
Enemy.MonsterZone[enemyzone].Id != _CardId.JackKnightOfTheGoldenBlossom &&
Enemy.MonsterZone[enemyzone].Id != _CardId.JackKnightOfTheLavenderDust &&
Enemy.MonsterZone[enemyzone].Id != _CardId.JackKnightOfTheVerdantGale &&
Enemy.MonsterZone[enemyzone].Id != _CardId.JackKnightOfTheWorldScar &&
Enemy.MonsterZone[enemyzone].Id != _CardId.MekkKnightMorningStar)
return false;
return true;
}

public bool NoJackKnightColumn(int enemyzone)
{
if (Enemy.MonsterZone[enemyzone] == null &&
(enemyzone == 2 || enemyzone == 4 || enemyzone == 0))
return true;
if (enemyzone == 1 || enemyzone == 5)
{
if (Enemy.MonsterZone[1] != null && (
Enemy.MonsterZone[1].Id == _CardId.JackKnightOfTheAmberShade ||
Enemy.MonsterZone[1].Id == _CardId.JackKnightOfTheAzureSky ||
Enemy.MonsterZone[1].Id == _CardId.JackKnightOfTheCobaltDepths ||
Enemy.MonsterZone[1].Id == _CardId.JackKnightOfTheCrimsonLotus ||
Enemy.MonsterZone[1].Id == _CardId.JackKnightOfTheGoldenBlossom ||
Enemy.MonsterZone[1].Id == _CardId.JackKnightOfTheLavenderDust ||
Enemy.MonsterZone[1].Id == _CardId.JackKnightOfTheVerdantGale ||
Enemy.MonsterZone[1].Id == _CardId.JackKnightOfTheWorldScar ||
Enemy.MonsterZone[1].Id == _CardId.MekkKnightMorningStar))
return false;
if (Enemy.MonsterZone[5] != null &&
(Enemy.MonsterZone[5].Id == _CardId.JackKnightOfTheAmberShade ||
Enemy.MonsterZone[5].Id == _CardId.JackKnightOfTheAzureSky ||
Enemy.MonsterZone[5].Id == _CardId.JackKnightOfTheCobaltDepths ||
Enemy.MonsterZone[5].Id == _CardId.JackKnightOfTheCrimsonLotus ||
Enemy.MonsterZone[5].Id == _CardId.JackKnightOfTheGoldenBlossom ||
Enemy.MonsterZone[5].Id == _CardId.JackKnightOfTheLavenderDust ||
Enemy.MonsterZone[5].Id == _CardId.JackKnightOfTheVerdantGale ||
Enemy.MonsterZone[5].Id == _CardId.JackKnightOfTheWorldScar ||
Enemy.MonsterZone[5].Id == _CardId.MekkKnightMorningStar))
return false;
return true;
}
if (enemyzone == 3 || enemyzone == 6)
{
if (Enemy.MonsterZone[3] != null &&
(Enemy.MonsterZone[3].Id == _CardId.JackKnightOfTheAmberShade ||
Enemy.MonsterZone[3].Id == _CardId.JackKnightOfTheAzureSky ||
Enemy.MonsterZone[3].Id == _CardId.JackKnightOfTheCobaltDepths ||
Enemy.MonsterZone[3].Id == _CardId.JackKnightOfTheCrimsonLotus ||
Enemy.MonsterZone[3].Id == _CardId.JackKnightOfTheGoldenBlossom ||
Enemy.MonsterZone[3].Id == _CardId.JackKnightOfTheLavenderDust ||
Enemy.MonsterZone[3].Id == _CardId.JackKnightOfTheVerdantGale ||
Enemy.MonsterZone[3].Id == _CardId.JackKnightOfTheWorldScar ||
Enemy.MonsterZone[3].Id == _CardId.MekkKnightMorningStar))
return false;
if (Enemy.MonsterZone[6] != null &&
(Enemy.MonsterZone[6].Id == _CardId.JackKnightOfTheAmberShade ||
Enemy.MonsterZone[6].Id == _CardId.JackKnightOfTheAzureSky ||
Enemy.MonsterZone[6].Id == _CardId.JackKnightOfTheCobaltDepths ||
Enemy.MonsterZone[6].Id == _CardId.JackKnightOfTheCrimsonLotus ||
Enemy.MonsterZone[6].Id == _CardId.JackKnightOfTheGoldenBlossom ||
Enemy.MonsterZone[6].Id == _CardId.JackKnightOfTheLavenderDust ||
Enemy.MonsterZone[6].Id == _CardId.JackKnightOfTheVerdantGale ||
Enemy.MonsterZone[6].Id == _CardId.JackKnightOfTheWorldScar ||
Enemy.MonsterZone[6].Id == _CardId.MekkKnightMorningStar))
return false;
return true;
}
if (Enemy.MonsterZone[enemyzone] != null &&
Enemy.MonsterZone[enemyzone].Id != _CardId.JackKnightOfTheAmberShade &&
Enemy.MonsterZone[enemyzone].Id != _CardId.JackKnightOfTheAzureSky &&
Enemy.MonsterZone[enemyzone].Id != _CardId.JackKnightOfTheCobaltDepths &&
Enemy.MonsterZone[enemyzone].Id != _CardId.JackKnightOfTheCrimsonLotus &&
Enemy.MonsterZone[enemyzone].Id != _CardId.JackKnightOfTheGoldenBlossom &&
Enemy.MonsterZone[enemyzone].Id != _CardId.JackKnightOfTheLavenderDust &&
Enemy.MonsterZone[enemyzone].Id != _CardId.JackKnightOfTheVerdantGale &&
Enemy.MonsterZone[enemyzone].Id != _CardId.JackKnightOfTheWorldScar &&
Enemy.MonsterZone[enemyzone].Id != _CardId.MekkKnightMorningStar)
return true;
return false;
}

public bool SameMonsterColumn(int botzone, int enemyzone)
{
if (botzone == 4 && enemyzone == 0)
return true;
if ((botzone == 3 || botzone == 6) && (enemyzone == 1 || enemyzone == 5))
return true;
if (botzone == 2 && enemyzone == 2)
return true;
if ((botzone == 1 || botzone == 5) && (enemyzone == 3 || enemyzone == 6))
return true;
if (botzone == 0 && enemyzone == 4)
return true;
return false;
}

protected DefaultExecutor(GameAI ai, Duel duel)
Expand Down Expand Up @@ -196,6 +386,131 @@ public override CardPosition OnSelectPosition(int cardId, IList<CardPosition> po
return 0;
}

public override int OnSelectPlace(int cardId, int player, int location, int available)
{
//Logger.DebugWriteLine("%%%%%%WindBot.Global.m_zone = " + Duel.Global.m_zone);
//Logger.DebugWriteLine("%%%%%%WindBot.Global.intial_zone = " + (byte)Duel.Global.intial_zone);
//Logger.DebugWriteLine("%%%%%%sWindBot.Global.m_type = " + Duel.Global.m_type);
Duel.Global.m_zone = 0;
if ((Duel.Global.m_type == 1 || Duel.Global.m_type == Zones.MainMonsterZones) &&
Enemy.HasInSpellZone(_CardId.TrueDepthsOfTheWorldLegacy))
{
for (int i = 4; i >= 0; i--)
{
if (Bot.MonsterZone[ReverseZone16bitTo32bit(Duel.Global.intial_zone)] == null &&
NoJackKnightColumn(ReverseBotEnemyZone(ReverseZone16bitTo32bit(Duel.Global.intial_zone))))
break;
if (NoJackKnightColumn(i) && Bot.MonsterZone[ReverseBotEnemyZone(i)] == null)
{
Duel.Global.m_zone = ReverseZoneTo16bit(ReverseBotEnemyZone(i));
// Logger.DebugWriteLine("%%%%%%selsectplacecheck" + i + " = " + Duel.Global.m_zone);
break;
}
// Logger.DebugWriteLine("%%%%%%selsectplacecheck"+ i+ " = " + Duel.Global.m_zone);
}
}
if ((Duel.Global.m_type == 1 || Duel.Global.m_type == Zones.MainMonsterZones) &&
Enemy.MonsterZone[5] != null &&
Enemy.MonsterZone[5].HasLinkMarker((int)LinkMarker.Top))
{
for (int i = 4; i >= 0; i--)
{
if (Bot.MonsterZone[ReverseZone16bitTo32bit(Duel.Global.intial_zone)] == null &&
Duel.Global.intial_zone != Zones.z3)
break;
if (i == 3) continue;
if (Bot.MonsterZone[i] == null)
{
Duel.Global.m_zone = ReverseZoneTo16bit(i);
// Logger.DebugWriteLine("%%%%%%selsectplacecheck" + i + " = " + Duel.Global.m_zone);
break;
}
// Logger.DebugWriteLine("%%%%%%selsectplacecheck" + i + " = " + Duel.Global.m_zone);
}
}
if ((Duel.Global.m_type == 1 || Duel.Global.m_type == Zones.MainMonsterZones) &&
Enemy.MonsterZone[6] != null &&
Enemy.MonsterZone[6].HasLinkMarker((int)LinkMarker.Top))
{
for (int i = 4; i >= 0; i--)
{
if (Bot.MonsterZone[ReverseZone16bitTo32bit(Duel.Global.intial_zone)] == null &&
Duel.Global.intial_zone != Zones.z1)
break;
if (i == 1) continue;
if (Bot.MonsterZone[i] == null)
{
Duel.Global.m_zone = ReverseZoneTo16bit(i);
break;
}
//Logger.DebugWriteLine("%%%%%%selsectplacecheck" + i + " = " + Duel.Global.m_zone);
}
}
if ((Duel.Global.m_type == 2 || Duel.Global.m_type == (int)CardType.Spell) &&
Enemy.HasInSpellZone(_CardId.WhisperOfTheWorldLegacy))
{
for (int i = 4; i >= 0; i--)
{
//Logger.DebugWriteLine("%%%%%%NoJackKnightColumn" + i + " = " + ReverseBotEnemyZone(ReverseZone16bitTo32bit(Duel.Global.intial_zone)));
if (Bot.SpellZone[ReverseZone16bitTo32bit(Duel.Global.intial_zone)] == null &&
NoJackKnightColumn(ReverseBotEnemyZone(ReverseZone16bitTo32bit(Duel.Global.intial_zone))))
break;
if (NoJackKnightColumn(i) && Bot.SpellZone[ReverseBotEnemyZone(i)] == null)
{
Duel.Global.m_zone = ReverseZoneTo16bit(ReverseBotEnemyZone(i));
//Logger.DebugWriteLine("%%%%%%selsectplacecheck" + i + " = " + Duel.Global.m_zone);
break;
}
// Logger.DebugWriteLine("%%%%%%selsectplacecheck" + i + " = " + Duel.Global.m_zone);
}
}
if (((Duel.Global.m_type == 2 || Duel.Global.m_type == (int)CardType.Spell) ||
(Duel.Global.m_type == 4 || Duel.Global.m_type == (int)CardType.Trap)) &&
Duel.Global.InfiniteTransience_zone != -1)
{
for (int i = 4; i >= 0; i--)
{
if (Bot.SpellZone[i] == null && ReverseBotEnemyZone(i) != Duel.Global.InfiniteTransience_zone)
Duel.Global.m_zone = ReverseZoneTo16bit(i);
}
}

if ((Duel.Global.m_type == 4 || Duel.Global.m_type == (int)CardType.Trap) &&
Enemy.HasInSpellZone(_CardId.KeyToTheWorldLegacy))
{
for (int i = 4; i >= 0; i--)
{

if (Bot.SpellZone[ReverseZone16bitTo32bit(Duel.Global.intial_zone)] == null &&
NoJackKnightColumn(ReverseBotEnemyZone(ReverseZone16bitTo32bit(Duel.Global.intial_zone))))
break;
if (NoJackKnightColumn(i) && Bot.SpellZone[ReverseBotEnemyZone(i)] == null)
{
Duel.Global.m_zone = ReverseZoneTo16bit(ReverseBotEnemyZone(i));
break;
}
}
}
if ((Duel.Global.m_type == 3 || Duel.Global.m_type == Zones.ExtraMonsterZones) &&
Enemy.HasInSpellZone(_CardId.TrueDepthsOfTheWorldLegacy))
{
for (int i = 5; i < 6; i++)
{
if (Bot.MonsterZone[ReverseZone16bitTo32bit(Duel.Global.intial_zone)] == null &&
NoJackKnightColumn(ReverseBotEnemyZone(ReverseZone16bitTo32bit(Duel.Global.intial_zone)))
)
break;
if (NoJackKnightColumn(i) && Bot.MonsterZone[ReverseBotEnemyZone(i)] == null)
{
Duel.Global.m_zone = ReverseZoneTo16bit(ReverseBotEnemyZone(i));
break;
}
}
}
if ((Duel.Global.m_zone & available) > 0)
return Duel.Global.m_zone & available;
return base.OnSelectPlace(cardId, player, location, available);
}
public override bool OnSelectBattleReplay()
{
if (Bot.BattlingMonster == null)
Expand Down
8 changes: 8 additions & 0 deletions Game/Duel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,13 @@ public int GetLocalPlayer(int player)
{
return IsFirst ? player : 1 - player;
}

public class Global
{
public static int m_type;
public static int m_zone;
public static int intial_zone = 2;
public static int InfiniteTransience_zone;
}
}
}
9 changes: 8 additions & 1 deletion Game/GameAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -947,9 +947,16 @@ public void SelectPosition(CardPosition pos)
m_position.Add(pos);
}

public void SelectPlace(int zones)
/// <summary>
/// parameter type:avoid choosing the place with column negate
/// </summary>
/// <param name="type">Use CardType or Zones(single way:1 for MainMonsterZone;2 for spell;4 for trap;3 for ExtraMonsterZone)</param>
public void SelectPlace(int zones, int type = 0)
{
m_place = zones;
Duel.Global.m_type = type;
Duel.Global.intial_zone = Zones.z2;
Duel.Global.intial_zone = zones;
}

public void SelectOption(int opt)
Expand Down