donnyandClaude Opus 5.5 0fd327e933
CI / build (push) Successful in 48s
feat(decisions): the decision seam, one IDecisionMaker asked at every prompt
GameBehavior asks YGOL_Decide at every prompt (idle, battle, cards, chain, yes/no, option, position, place,
sum, counter, declarations, sort, RPS, turn order). With no decision maker for the seat (the default) that is
the GameAI call and nothing else: the built-in brain plays as before (same 100-duel report, 67-33, avg 18.5).
With one, the prompt goes out as a plain-data DecisionRequest (kind, legal options, the seat's DuelView) and
comes back as option indices; null, an exception or an illegal answer falls back to the executor.

A seat picks a maker with Decisions=<name> (arena: --decisionsA/--decisionsB); DecisionMakers.Register names
one. Built in: builtin and random (a random legal answer read from the request's JSON). Tests: 100 random-vs-
random duels through the seam with 0 errors and no fallback, builtin == no token, Smart beats random 100-0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 18:29:33 -07:00

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, Host/BotHost.cs (the contract with the host) and Decisions/ (the decision seam).
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. CharacterRegistry is in the library without its UniTask surface. The game keeps its own Init() / Loaded: CharacterRegistry.Scan(CharacterRegistry.Root) on the thread pool, then CharacterRegistry.Publish(scan) on the main thread (exactly what Init did). Hosts without a player loop call CharacterRegistry.LoadFromDisk().
  • Internals. The game calls internal members of WindBot (WindBot.Program.YGOL_Main, ...). The library keeps them internal and lets Assembly-CSharp, Assembly-CSharp-Editor, BotArena and 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.

The decision seam: who answers a seat's prompts

One bot plays the same everywhere a duel runs: a solo duel in the game (engine and bots in the game's process, no network, offline), a LAN room on a player's PC, a dedicated-server room, the headless arena. Every one of them feeds the seat's WindBot GameBehavior, and every prompt the engine sends that seat (main phase or battle phase action, cards to pick, chain or not, yes or no, a zone, a position, a declaration, sort, rock-paper-scissors, turn order) goes through one point before WindBot's AI: GameBehavior.YGOL_Decide (src/YGOLegacy.Bots/WindBot/Game/GameBehavior.YGOL_Decisions.cs).

namespace YGOLegacy.Bots.Decisions
public interface IDecisionMaker
{
    Decision Decide(DecisionRequest request);   // null = let the seat's own brain answer
}
  • The built-in brain is the seat's WindBot executor: SmartExecutor for character decks, Lucky for Dovphin, a deck executor otherwise. A seat without a decision maker (the default, and every seat today) is answered by it exactly as before: YGOL_Decide calls the GameAI and builds nothing else.
  • Another decision maker is chosen per seat by the WindBot token Decisions=<name> (the arena: --decisionsA/--decisionsB <name>) and registered by name with DecisionMakers.Register(name, seat => maker) by the host or a plug-in. builtin (or no token) is the executor; an unknown name is logged and gets the executor. Built in: random, a uniformly random legal answer that reads only each request's JSON (a baseline, and the seam's own end-to-end test).
  • The question is a DecisionRequest: kind (DecisionKind: idle, battle, card, tribute, unselectCard, chain, effectYesNo, yesNo, option, position, place, sum, counter, attribute, race, number, announceCard, sort, rockPaperScissors, turnOrder), the seat, min/max/cancelable, the engine's hint and description, the legal options (each with its action, its card as a CardView, its description and value), and duel, a DuelView of what this seat sees (turn, phase, LP, its hand and Extra Deck, both fields, graveyards, banished, deck counts, the chain; hidden cards have code 0). The answer is a Decision: the chosen option indices (counter prompts: one count per option). All plain public fields: Newtonsoft (or any JSON) round-trips them; version names the format.
  • Fallback. A maker that returns null, throws, or answers something illegal (an index that is not an option, a count outside min..max) gets a [YGOL decisions] warning and the executor answers that prompt; the duel goes on. So a maker can take over some kinds and leave the rest (random leaves sums and counters). The executor's own plans assume it made the earlier choices; mixing is legal, not necessarily good play.
  • A remote brain (an LLM through OpenRouter, a model on a GPU box) is an IDecisionMaker that sends the request and waits for the answer: Decide is called on the bot's thread and the duel waits for it, the same in all four places. Its time limit, retries and fallback are its own; returning null hands the prompt back. No remote maker is built yet.

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), the decision seam (the registry, JSON round trips, the random maker's ranges), and the published Linux arena on the fixture: 100 duels of AI_OldSchool against itself (both seats the Smart brain) with 0 errors; the same --seed giving the same report at --parallel 4 and --parallel 2 (clocks aside); 100 duels with both seats answered through the seam by random (0 errors, no fallback); Decisions=builtin giving the same duels as no token; and the Smart brain beating random.

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.

S
Description
The bots of Yu-Gi-Oh! Legacy (WindBot, the SmartExecutor brain, the in-process duel host) as a library the game and the server take as a release, plus the headless Bot Arena.
Readme
980 KiB
0 Stars 1 Watchers 0 Forks
v0.2.0
Latest
2026-10-19 18:40:03 -07:00
Languages
C# 96.7%
Lua 3.1%
Python 0.1%