Liangzx Administrator
| Subject: How to Create your own YGOPRO AI Fri Feb 07, 2020 8:18 pm | |
| WindBot was developed in C#. C# is relatively easy to use, so writing an AI is not difficult. This article takes the preparation of a track card group as an example to introduce the method of writing WindBot AI. - Requirements :
1. Visual Studio Tested on VS2015, VS2010 is theoretically available. Download VS2015 [You must be registered and logged in to see this link.]2. Basic programming knowledge 3. PC version of YGOPRO Download YGOPRO [You must be registered and logged in to see this link.]4. Basic YGOPro knowledge 5. Winbot Master file [You must be registered and logged in to see this link.]Extract the .zip into your YGOPRO folder
After you fulfill the requirements, lets get started - 1. Make a Deck for your AI:
-Create a new deck in YGOPRO [You must be registered and logged in to see this image.]-Card decks are prioritized for ease of use. The more usage of a card, the harder it is to write AI. -Name the ydk file AI_Lightsworn (AI_DeckName) and place it in the decks folder of windbot. [You must be registered and logged in to see this image.]Note : Make sure you know how to play the deck you made
- 2. Create an Executor file for the AI deck you made:
Executor (not related to the Java one) used to specify the use of each card for each deck. -Open the existing executor file in YGOPRO/winbot-master/Game/AI/Decks -Save it as "LightswornExecutor.cs" (DeckNameExecutor.cs) -Select all (Ctrl+A), then delete (Del) all codes in it, then press save (Save) -Write the following code in it: - Code:
using YGOSharp.OCGWrapper.Enums; using System.Collections.Generic; using WindBot; using WindBot.Game; using WindBot.Game.AI;
namespace WindBot.Game.AI.Decks { [Deck("Lightsworn", "AI_Lightsworn")] public class LightswornExecutor : DefaultExecutor {
public LightswornExecutor(GameAI ai, Duel duel) : base(ai, duel) {
}
} }
You can see that the LightswornExecutor under WindBot.Game.AI.Decks inherits the DefaultExecutor. The first parameter of the Deck property is the deck name, and the second is the deck file name. -Press Save
- 3. First look of your AI:
-On Visual Studio, press "Ctrl+Shift+O" -Open WindBot.sln in windbot-master folder -Press F5 and let it load to make the bin folder, then close it -Copy cards.cdb from your "YGOPRO/locales/en-US/" (if you're using YGOPROES or KoishiPro) to "windbot-master/bin/Debug/" -Open YGOPRO then make a host in Lan Mode -On Visual Studio, click Debug > WindBot Properties [You must be registered and logged in to see this image.]this window tab should appear -In "Command Line Arguments" box, type "Deck=Lightsworn" (Deck=DeckName) without "" -Press F5 -If everything is fine, you can see the AI join the room and be ready. NOTE : If AI does not appear, please make sure that Windbot is started before the host is established. If the AI is not ready in the host room, please make sure the deck files are placed in the correct location and WindBot has the correct cards.cdb. But after starting the game, we will find that AI will not play any cards. This is because we have not specified how to use AI cards. WindBot will only use the card specified in the Executor of the deck, and the other cards will not do anything, so all we have to do is write usage for each card.
- 4. Create a card name class:
To facilitate specifying the card name in the code, we create a CardId class and write each card name as a constant. -Click "LightswornExecutor.cs" in the Visual Studio window tab Create a CardId class in LightswornExecutor.cs and define the ID of each card in the card group inside "public class LightswornExecutor : DefaultExecutor"'s bracket : - Code:
public class CardId { public const int JudgmentDragon = 57774843; public const int Wulf = 58996430; public const int Garoth = 59019082; public const int Raiden = 77558536; public const int Lyla = 22624373; public const int Felis = 73176465; public const int Lumina = 95503687; public const int Minerva = 40164421; public const int Ryko = 21502796; public const int PerformageTrickClown = 67696066; public const int Goblindbergh = 25259669; public const int ThousandBlades = 1833916; public const int Honest = 37742478; public const int GlowUpBulb = 67441435;
public const int SolarRecharge = 691925; public const int GalaxyCyclone = 5133471; public const int HarpiesFeatherDuster = 18144506; public const int ReinforcementOfTheArmy = 32807846; public const int MetalfoesFusion = 73594093; public const int ChargeOfTheLightBrigade = 94886282;
public const int Michael = 4779823; public const int MinervaTheExalted = 30100551; public const int TrishulaDragonOfTheIceBarrier = 52687916; public const int ScarlightRedDragonArchfiend = 80666118; public const int PSYFramelordOmega = 74586817; public const int PSYFramelordZeta = 37192109; public const int NumberS39UtopiatheLightning = 56832966; public const int Number39Utopia = 84013237; public const int CastelTheSkyblasterMusketeer = 82633039; public const int EvilswarmExcitonKnight = 46772449; public const int DanteTravelerOfTheBurningAbyss = 83531441; public const int DecodeTalker = 1861629; public const int MissusRadiant = 3987233; }
the code should look like this [You must be registered and logged in to see this image.]NOTE : If you feel that typing the full card name is too difficult, you can simplify them, but this may cause confusion later.
- 5. The simplest Executor, let AI activate Harpies Feather Duster and Normal Summon Raiden:
Other than for the deck's Executor, each card should have one or more Executors. heres the two simplest Executors in the constructor of LightswornExecutor inside "public LightswornExecutor(GameAI ai, Duel duel)"'s bracket : - Code:
AddExecutor(ExecutorType.Activate, CardId.HarpiesFeatherDuster);
This allows the AI to activate HarpiesFeatherDuster when it can be activated. - Code:
AddExecutor(ExecutorType.Summon, CardId.Raiden);
This allows the AI to normal summon Raiden when it can be summoned normally. the code should look like this [You must be registered and logged in to see this image.]Q : In the main stage of AI, if there are both Raiden and Harpies Feather Duster in AI's hand. How to decide the order? A : The answer is based on the order in which the Executor is registered, the first operation is the first registration. Whenever the AI can activate an effect or summon, it will check the Executor of the current deck, and determine whether the operations in it are available in order, and if it is available, perform the operation. Then it will start again from the beginning, because YGOPro does not support 2 operations at a time, but resends the list of operations that the client can perform after performing one operation.
- 6. Slightly more complicated Executor, only activate Reinforcement of the Army if the conditions are met, and select the designated card:
Now let ’s take a look at the next card. What if we want to activate RotA and add Raiden if theres no Raiden in hand, and take Goblindbergh if theres Raiden in hand? -Create a function inside "public class LightswornExecutor : DefaultExecutor"'s bracket - Code:
private bool ReinforcementOfTheArmyEffect() { if (!Bot.HasInHand(CardId.Raiden)) { AI.SelectCard(CardId.Raiden); return true; } else if (!Bot.HasInHand(CardId.Goblindbergh)) { AI.SelectCard(CardId.Goblindbergh); return true; } return false; }
-Then add an Executor inside "public LightswornExecutor(GameAI ai, Duel duel)"'s bracket - Code:
AddExecutor(ExecutorType.Activate, CardId.ReinforcementOfTheArmy, ReinforcementOfTheArmyEffect);
In this way, when ReinforcementOfTheArmyEffect returns true, the reinforcement will be activated. Bot is an instance of ClientField with methods such as GetMonsters, HasInHand. The role of AI.SelectCard is to select a card in advance. Called before deciding to activate an effect, and then when you want to select a card, it will be selected according to the set goal.
|
|