Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
yugioh-legacy-bots
The bots of Yu-Gi-Oh! Legacy, as one library both the game and the server take as a release, the way both take
the engine (donny/yugioh-legacy-engine): WindBot, the parts of YGOSharp it uses, the SmartExecutor brain, the
in-process duel host, the character registry and the roster (YGOLegacy.Bots.dll), and the headless Bot Arena
on top of it (BotArena, Linux and Windows). The game plays these bots in solo duels; the server runs the arena.
The code came from the Unity repo (donny/yugioh-legacy-unity, branch dev, commit
19c6158197a0a8f0817dd0924bb9a6a987c2bfc5); the first commit here is that code, verbatim, in this layout.
Layout
| Path | What |
|---|---|
src/YGOLegacy.Bots/ |
The library: .NET Standard 2.1, C# 9, no Unity reference (Unity compiles against it). WindBot/, YGOSharp/ (the client, the card managers, the enums), Bot/ (SmartExecutor, BoardEvaluator, BrainRules, EffectSimulator, BattlePredictor, DuelStateBus, LocalDuelHost, LoopbackBotSeat, Lookahead, ArenaReport), Characters/, Services/BotRoster.cs, and Host/BotHost.cs, the contract. |
src/BotArena/ |
The headless arena, .NET 8, linux-x64 and win-x64. Its own README.md has the options, the report and how it works. |
tests/YGOLegacy.Bots.Tests/ |
NUnit: the library through its contract, and the Linux arena end to end. |
tests/fixture/ |
game/, the smallest game root the tests duel on, and make-fixture.py, which builds it (see its README.md). |
engine.json |
The pin: the engine release this repo builds and tests against (that release's engine.json, verbatim). |
build/fetch-engine.sh |
Downloads the pinned release into .engine/ and refuses one whose engine.json is not the pin. |
Dockerfile |
Every build and test. There is no dotnet on the build hosts. |
.gitea/workflows/ci.yml |
CI on every push; the release on a vX.Y.Z tag. |
CHANGELOG.md |
One section per release; it is the release's body. |
The contract: what the game implements
The library reaches the program that runs it only through YGOLegacy.Bots.BotHost. The host sets it once at
start-up, before the first bot is built and before the character registry loads. Every path the bots read is
relative to the current directory, which must be the game root (Data/locales/<locale>/cards.cdb,
Expansions/*.cdb, Data/Windbot/Decks/, Deck/, Data/Characters/).
BotHost. |
Interface | The game (YGO-156) | The arena (src/BotArena/ArenaHost.cs) |
|---|---|---|---|
Log |
IBotLog: Info, Warning, Error |
UnityEngine.Debug.Log / LogWarning / LogError |
stderr, into the worker log |
Cards |
ICardDatabase: IDbConnection Connect(string path), not yet opened |
new Mono.Data.Sqlite.SqliteConnection("Data Source=" + path) |
Microsoft.Data.Sqlite, read-only, shared |
Files |
IGameFiles: Locale, ExpansionCardDatabases() |
Language.GetConfig(), ResourceManager.GetAllCdbInZipPaths() |
--locale; the .cdb it extracts from Expansions/*.ypk |
DeckLimits |
IDeckLimits: DeckCaps For(string rulesetId) (the deck file's #ruleset, or null) |
DeckLimits.For(id) → new DeckCaps(r.MainMax, r.ExtraLimit(), r.SideMax), read at each call |
the default, 60 / 99 / 15 |
BotConf |
IBotConf: Entries() (BotConfEntry name, command, desc, flags), Reload() |
SoloLoader.Catalog (initialised if not ready), SoloLoader.Reload() |
Data/locales/<lang>/bot.conf |
Defaults when a host sets nothing: Log the console, Files en-US with no expansion databases, DeckLimits
60 / 99 / 15, BotConf empty (the roster then uses its built-in Dovphin command). Cards has no default: loading
the card databases without it throws.
Two more things the game does on its side:
- Characters.
CharacterRegistryis in the library without its UniTask surface. The game keeps its ownInit()/Loaded:CharacterRegistry.Scan(CharacterRegistry.Root)on the thread pool, thenCharacterRegistry.Publish(scan)on the main thread (exactly whatInitdid). Hosts without a player loop callCharacterRegistry.LoadFromDisk(). - Internals. The game calls internal members of WindBot (
WindBot.Program.YGOL_Main, ...). The library keeps them internal and letsAssembly-CSharp,Assembly-CSharp-Editor,BotArenaand the tests see them (Properties/AssemblyInfo.cs).
Namespaces are the ones the game already uses (WindBot.*, YGOSharp.*, YGOLegacy.Bot, YGOLegacy.Characters,
YGOLegacy.Services for BotRoster / BotDef), so the game's callers do not change. What stays in the game:
GamePaths, DeckLimits / RulesetDeck / DeckPool and the rulesets, SoloLoader, CharacterLoader,
VoiceLineStore, the in-editor arena (Core/Bot/BotArena.cs) and YGOSharp's server side (YGOSharp/YGOSharp/*,
Api.cs, Duel.cs, MtRandom.cs, the Async* and NetworkServer files).
The game references YGOLegacy.Bots.dll beside the engine's YGOLegacy.Engine.dll (same release as
bots.json's engine) and its own Newtonsoft.Json (Unity's com.unity.nuget.newtonsoft-json, 13.x). Neither is
in bots-lib.zip.
Build and test
docker build --target test . # build, then every test (the Linux arena plays the fixture duels)
docker build --target dist -o out . # out/lib, out/bot-arena-linux-x64, out/bot-arena-win-x64
docker build --target release -o dist . # the release assets
With a dotnet 8 SDK instead: build/fetch-engine.sh, then dotnet build src/YGOLegacy.Bots, dotnet publish src/BotArena -r linux-x64 --self-contained, BOTARENA_EXE=<that>/BotArena dotnet test tests/YGOLegacy.Bots.Tests.
The tests: the library through BotHost (cards, deck caps and #ruleset, the roster's deck → character → brain
and its Dovphin fallback, a broken character logged, the game's scan-then-publish), and the published Linux arena
on the fixture: 100 duels of AI_OldSchool against itself (both seats the Smart brain) with 0 errors, and the
same --seed giving the same report at --parallel 4 and --parallel 2 (clocks aside).
Engine pin
engine.json is the engine release's own engine.json. build/fetch-engine.sh downloads that version's
ygol-engine-binding.zip, ygol-engine-linux-x64.tar.gz and ygol-engine-win64.zip and refuses a bundle that
disagrees with the pin. The library compiles against the binding; each arena ships its platform's native library
and the binding next to the exe. Moving to a new engine release: copy that release's engine.json over this
one, run docker build --target test ., commit, release. The game and the server should be on the same engine
release as the bots they take (bots.json's engine).
Release
# CHANGELOG.md: add "## vX.Y.Z — <date>" (the section is the release body), commit
git tag vX.Y.Z && git push origin main vX.Y.Z
The run (Actions tab) builds, tests and packs; the release named after the tag appears only when all of that passed. A tag whose release already exists is refused: a bad release gets a new patch tag, never a re-upload.
https://gitea.dev.blueoceanswim.com/donny/yugioh-legacy-bots/releases/download/<tag>/<asset>:
| Asset | Contents |
|---|---|
bots-lib.zip |
YGOLegacy.Bots.dll, YGOLegacy.Bots.pdb, bots.json |
bot-arena-linux-x64.tar.gz |
bot-arena-linux-x64/: BotArena (self-contained), libygol-engine.so, YGOLegacy.Engine.dll, engine.json, bots.json |
bot-arena-win-x64.zip |
bot-arena-win-x64/: BotArena.exe (self-contained), ygol-engine.dll, YGOLegacy.Engine.dll, engine.json, bots.json |
bots.json |
{ version, engine }: this release and the engine release it was built and tested against |
YGOLegacy.Bots.BotsBuild.Version and .Engine carry the same two strings inside the library.