test: the library through BotHost and 100 Linux arena duels on a fixture game root
tests/fixture/game is built by make-fixture.py from the Unity repo's Data/ at dev 19c6158 (AI_OldSchool, its 17 cards and scripts, bot.conf) plus a character that owns the deck. The arena tests run the published Linux exe: 100 Smart-vs-Smart duels with 0 errors, and --seed 7 giving the same report at --parallel 4 and 2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3bbfe08ab1
commit
ff8eb61bc2
12 files changed
+4319
No files matched your search
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace YGOLegacy.Bots.Tests
|
||||
{
|
||||
/// The published Linux arena, end to end: `--host local` on the pinned engine, on tests/fixture/game.
|
||||
[TestFixture, NonParallelizable]
|
||||
public class ArenaTests
|
||||
{
|
||||
private const int Duels = 100;
|
||||
private const int Seed = 7;
|
||||
|
||||
// What differs between two runs of the same duels: clocks, the worker count and where the report went.
|
||||
private static readonly HashSet<string> Clocks = new()
|
||||
{
|
||||
"startedAt", "totalSeconds", "wallClockSeconds", "durationSeconds", "coreMs", "summary", "reportPath",
|
||||
"workers", "outPath",
|
||||
};
|
||||
|
||||
private static string Exe
|
||||
{
|
||||
get
|
||||
{
|
||||
var exe = Environment.GetEnvironmentVariable("BOTARENA_EXE");
|
||||
if (string.IsNullOrEmpty(exe)) Assert.Ignore("BOTARENA_EXE is not set (the Docker test stage sets it)");
|
||||
return exe;
|
||||
}
|
||||
}
|
||||
|
||||
private static (int code, string stdout, string stderr) Run(string root, params string[] args)
|
||||
{
|
||||
var psi = new ProcessStartInfo(Exe)
|
||||
{
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false,
|
||||
};
|
||||
psi.ArgumentList.Add("--root");
|
||||
psi.ArgumentList.Add(root);
|
||||
foreach (var a in args) psi.ArgumentList.Add(a);
|
||||
using var p = Process.Start(psi);
|
||||
var stderr = p.StandardError.ReadToEndAsync();
|
||||
var stdout = p.StandardOutput.ReadToEnd();
|
||||
if (!p.WaitForExit(600_000)) { p.Kill(true); Assert.Fail("the arena did not finish in 10 minutes"); }
|
||||
TestContext.Progress.WriteLine(stdout.Trim());
|
||||
return (p.ExitCode, stdout, stderr.Result);
|
||||
}
|
||||
|
||||
private static JObject Duel(string root, int n, int parallel, int seed, string outFile)
|
||||
{
|
||||
var (code, stdout, stderr) = Run(root, "--deckA", "AI_OldSchool", "--deckB", "AI_OldSchool",
|
||||
"--n", n.ToString(), "--parallel", parallel.ToString(), "--seed", seed.ToString(), "--host", "local",
|
||||
"--out", outFile);
|
||||
Assert.That(code, Is.EqualTo(0), "exit code; stderr:\n" + stderr);
|
||||
return JObject.Parse(File.ReadAllText(outFile));
|
||||
}
|
||||
|
||||
private static JToken WithoutClocks(JToken token)
|
||||
{
|
||||
var copy = token.DeepClone();
|
||||
foreach (var p in copy.SelectTokens("$..*").OfType<JValue>().Select(v => v.Parent).OfType<JProperty>().ToList())
|
||||
if (Clocks.Contains(p.Name)) p.Remove();
|
||||
return copy;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HundredDuelsOfABotDeckAgainstItselfHaveNoErrors()
|
||||
{
|
||||
var root = Fixture.CopyRoot();
|
||||
var report = Duel(root, Duels, 4, Seed, Path.Combine(root, "run-1.json"));
|
||||
TestContext.Progress.WriteLine("winsA " + report["winsA"] + ", winsB " + report["winsB"] + ", draws " + report["draws"]
|
||||
+ ", errors " + report["errors"] + ", average turns " + report["averageTurns"]);
|
||||
Assert.That((string)report["status"], Is.EqualTo("done"));
|
||||
Assert.That((int)report["completed"], Is.EqualTo(Duels));
|
||||
Assert.That((int)report["errors"], Is.EqualTo(0), string.Join("\n", report["duels"].Where(d => d["error"]?.Type == JTokenType.String).Select(d => d["index"] + ": " + d["error"])));
|
||||
Assert.That((int)report["winsA"] + (int)report["winsB"] + (int)report["draws"], Is.EqualTo(Duels));
|
||||
Assert.That((string)report["nameA"], Is.EqualTo("Old School A"), "the deck's owning character names the seat");
|
||||
Assert.That((string)report["commandA"], Does.Contain("Deck=Smart"), "and its brain plays it");
|
||||
Assert.That(Directory.GetFiles(Path.Combine(root, "Data", "BotArena"), "*.json"), Has.Length.EqualTo(1), "the canonical report");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheSameSeedGivesTheSameReport()
|
||||
{
|
||||
var root = Fixture.CopyRoot();
|
||||
var first = Duel(root, Duels, 4, Seed, Path.Combine(root, "seed-1.json"));
|
||||
var second = Duel(root, Duels, 2, Seed, Path.Combine(root, "seed-2.json"));
|
||||
Assert.That((int)first["completed"], Is.EqualTo(Duels));
|
||||
var a = WithoutClocks(first);
|
||||
var b = WithoutClocks(second);
|
||||
Assert.That(JToken.DeepEquals(a, b), Is.True, "reports differ:\n" + a + "\n----\n" + b);
|
||||
var other = WithoutClocks(Duel(root, Duels, 4, Seed + 1, Path.Combine(root, "seed-3.json")));
|
||||
Assert.That(JToken.DeepEquals(a["duels"], other["duels"]), Is.False, "another seed plays other duels");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HelpAndBadArguments()
|
||||
{
|
||||
var root = Fixture.CopyRoot();
|
||||
Assert.That(Run(root, "--help").code, Is.EqualTo(0));
|
||||
Assert.That(Run(root, "--deckA", "AI_OldSchool").code, Is.EqualTo(2), "--deckB missing");
|
||||
Assert.That(Run(root, "--deckA", "AI_OldSchool", "--deckB", "AI_OldSchool", "--host", "wasm").code, Is.EqualTo(2));
|
||||
Assert.That(Run(root, "--deckA", "AI_OldSchool", "--deckB", "AI_OldSchool", "--host", "server").code, Is.EqualTo(2), "server is Windows only");
|
||||
var (code, stdout, _) = Run(root, "--deckA", "No Such Deck", "--deckB", "AI_OldSchool", "--n", "1");
|
||||
Assert.That(code, Is.EqualTo(1), "nothing played");
|
||||
Assert.That(stdout, Does.Contain("bad deck A"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
using YGOLegacy.Bots;
|
||||
|
||||
namespace YGOLegacy.Bots.Tests
|
||||
{
|
||||
/// tests/fixture/game, copied to a fresh folder per use: the arena writes Data/BotArena/ under its root.
|
||||
internal static class Fixture
|
||||
{
|
||||
public static string Source
|
||||
{
|
||||
get
|
||||
{
|
||||
var dir = new DirectoryInfo(TestContext.CurrentContext.TestDirectory);
|
||||
while (dir != null && !File.Exists(Path.Combine(dir.FullName, "engine.json")))
|
||||
dir = dir.Parent;
|
||||
if (dir == null) throw new DirectoryNotFoundException("repo root (engine.json) not found above " + TestContext.CurrentContext.TestDirectory);
|
||||
return Path.Combine(dir.FullName, "tests", "fixture", "game");
|
||||
}
|
||||
}
|
||||
|
||||
public static string CopyRoot()
|
||||
{
|
||||
var root = Path.Combine(Path.GetTempPath(), "ygol-bots-tests", Guid.NewGuid().ToString("N"));
|
||||
Copy(Source, root);
|
||||
return root;
|
||||
}
|
||||
|
||||
private static void Copy(string from, string to)
|
||||
{
|
||||
Directory.CreateDirectory(to);
|
||||
foreach (var file in Directory.GetFiles(from))
|
||||
File.Copy(file, Path.Combine(to, Path.GetFileName(file)));
|
||||
foreach (var dir in Directory.GetDirectories(from))
|
||||
Copy(dir, Path.Combine(to, Path.GetFileName(dir)));
|
||||
}
|
||||
}
|
||||
|
||||
/// A host as the game would write one, in memory.
|
||||
internal sealed class TestHost : IBotLog, ICardDatabase, IGameFiles, IDeckLimits, IBotConf
|
||||
{
|
||||
public readonly List<string> Lines = new();
|
||||
public DeckCaps Caps = new(60, 99, 15);
|
||||
public readonly List<string> RulesetsAsked = new();
|
||||
public readonly List<BotConfEntry> Bots = new();
|
||||
|
||||
public void Install()
|
||||
{
|
||||
BotHost.Log = this;
|
||||
BotHost.Cards = this;
|
||||
BotHost.Files = this;
|
||||
BotHost.DeckLimits = this;
|
||||
BotHost.BotConf = this;
|
||||
}
|
||||
|
||||
public void Info(string message) { lock (Lines) Lines.Add(message); }
|
||||
public void Warning(string message) { lock (Lines) Lines.Add("[warn] " + message); }
|
||||
public void Error(string message) { lock (Lines) Lines.Add("[error] " + message); }
|
||||
|
||||
public IDbConnection Connect(string path)
|
||||
=> new Microsoft.Data.Sqlite.SqliteConnection("Data Source=" + path + ";Mode=ReadOnly");
|
||||
|
||||
public string Locale => "en-US";
|
||||
public IReadOnlyList<string> ExpansionCardDatabases() => Array.Empty<string>();
|
||||
|
||||
public DeckCaps For(string rulesetId)
|
||||
{
|
||||
RulesetsAsked.Add(rulesetId);
|
||||
return Caps;
|
||||
}
|
||||
|
||||
public IReadOnlyList<BotConfEntry> Entries() => Bots;
|
||||
public void Reload() { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
using YGOLegacy.Characters;
|
||||
using YGOLegacy.Services;
|
||||
|
||||
namespace YGOLegacy.Bots.Tests
|
||||
{
|
||||
/// The library reaches the game only through BotHost. These run in one process and share WindBot's statics,
|
||||
/// so they run one at a time, from a copy of the fixture as the current directory (the game root).
|
||||
[TestFixture, NonParallelizable]
|
||||
public class HostTests
|
||||
{
|
||||
private string root;
|
||||
private string cwd;
|
||||
private TestHost host;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void Load()
|
||||
{
|
||||
cwd = Directory.GetCurrentDirectory();
|
||||
root = Fixture.CopyRoot();
|
||||
Directory.SetCurrentDirectory(root);
|
||||
host = new TestHost();
|
||||
host.Install();
|
||||
WindBot.Program.InitDatas("cards.cdb");
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void Restore() => Directory.SetCurrentDirectory(cwd);
|
||||
|
||||
[Test]
|
||||
public void TheCardDatabaseLoadsThroughTheHost()
|
||||
{
|
||||
var card = YGOSharp.OCGWrapper.NamedCard.Get(11091375);
|
||||
Assert.That(card, Is.Not.Null);
|
||||
Assert.That(card.Name, Is.EqualTo("Luster Dragon"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ADeckLoadsUnderTheHostsCaps()
|
||||
{
|
||||
host.Caps = new DeckCaps(60, 99, 15);
|
||||
var deck = WindBot.Game.Deck.Load("AI_OldSchool");
|
||||
Assert.That(deck, Is.Not.Null);
|
||||
Assert.That(deck.Cards.Count, Is.EqualTo(40));
|
||||
Assert.That(host.RulesetsAsked[^1], Is.Null, "the deck file has no #ruleset line");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ADeckOverTheHostsMainCapIsRefused()
|
||||
{
|
||||
host.Caps = new DeckCaps(39, 99, 15);
|
||||
try { Assert.That(WindBot.Game.Deck.Load("AI_OldSchool"), Is.Null); }
|
||||
finally { host.Caps = new DeckCaps(60, 99, 15); }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheRulesetLineIsPassedToTheHost()
|
||||
{
|
||||
var file = Path.Combine("Data", "Windbot", "Decks", "AI_Ruleset.ydk");
|
||||
File.WriteAllText(file, "#ruleset goat\n" + File.ReadAllText(Path.Combine("Data", "Windbot", "Decks", "AI_OldSchool.ydk")));
|
||||
Assert.That(WindBot.Game.Deck.Load("AI_Ruleset"), Is.Not.Null);
|
||||
Assert.That(host.RulesetsAsked[^1], Is.EqualTo("goat"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheDeckDecidesTheBrain()
|
||||
{
|
||||
CharacterRegistry.LoadFromDisk();
|
||||
var bot = BotRoster.ForDeck("AI_OldSchool");
|
||||
Assert.That(bot.characterId, Is.EqualTo("fixture-oldschool"));
|
||||
Assert.That(bot.windBotCommand, Is.EqualTo("Name=\"Old School\" Deck=Smart"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ADeckNoCharacterOwnsGetsBotConfsDovphin()
|
||||
{
|
||||
CharacterRegistry.LoadFromDisk();
|
||||
host.Bots.Clear();
|
||||
host.Bots.Add(new BotConfEntry { name = "Dovphin", command = "Name=Dovphin Deck=Lucky Dialog=Ghoul.EN", desc = "", flags = new[] { "SELECT_DECKFILE" } });
|
||||
Assert.That(BotRoster.ForDeck("Nobody/Owns This").windBotCommand, Is.EqualTo("Name=Dovphin Deck=Lucky Dialog=Ghoul.EN"));
|
||||
host.Bots.Clear();
|
||||
Assert.That(BotRoster.ForDeck("Nobody/Owns This").windBotCommand, Is.EqualTo("Name=Dovphin Deck=Lucky"), "no bot.conf: the built-in command");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ABrokenCharacterIsLoggedThroughTheHost()
|
||||
{
|
||||
var dir = Path.Combine("Data", "Characters", "broken");
|
||||
Directory.CreateDirectory(dir);
|
||||
File.WriteAllText(Path.Combine(dir, "character.json"), "{ not json");
|
||||
try
|
||||
{
|
||||
CharacterRegistry.LoadFromDisk();
|
||||
Assert.That(host.Lines, Has.Some.StartsWith("[error] [YGOL characters] Data/Characters/broken/character.json"));
|
||||
Assert.That(CharacterRegistry.ById("fixture-oldschool"), Is.Not.Null, "a broken character never breaks the rest");
|
||||
}
|
||||
finally { Directory.Delete(dir, true); }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheGameCanScanOffThreadAndPublishLater()
|
||||
{
|
||||
var scan = CharacterRegistry.Scan(CharacterRegistry.Root);
|
||||
Assert.That(scan.found, Has.Some.Matches<Character>(c => c.id == "fixture-oldschool"));
|
||||
CharacterRegistry.Publish(scan);
|
||||
Assert.That(CharacterRegistry.IsLoaded, Is.True);
|
||||
Assert.That(CharacterRegistry.ForDeck("AI_OldSchool")?.id, Is.EqualTo("fixture-oldschool"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace YGOLegacy.Bots.Tests
|
||||
{
|
||||
public class BuildTests
|
||||
{
|
||||
[Test]
|
||||
public void TheLibraryNamesTheEngineReleaseItWasBuiltOn()
|
||||
{
|
||||
Assert.That(BotsBuild.Engine, Is.EqualTo(YGOLegacy.Engine.EngineBinding.Version), "engine.json's version is the binding it compiled against");
|
||||
var want = System.Environment.GetEnvironmentVariable("BOTS_VERSION");
|
||||
if (!string.IsNullOrEmpty(want)) Assert.That(BotsBuild.Version, Is.EqualTo(want));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<!-- The library through its contract (BotHost) and the Linux arena end to end, on tests/fixture/game.
|
||||
BOTARENA_EXE names the published arena (the Docker test stage sets it). -->
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<IsPackable>false</IsPackable>
|
||||
<NoWarn>$(NoWarn);CS0618</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../../src/YGOLegacy.Bots/YGOLegacy.Bots.csproj" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="NUnit" Version="3.14.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.8" />
|
||||
<Reference Include="YGOLegacy.Engine">
|
||||
<HintPath>$(EngineDir)YGOLegacy.Engine.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,17 @@
|
||||
# tests/fixture
|
||||
|
||||
`game/` is the smallest game root the tests duel on: one deck (`Data/Windbot/Decks/AI_OldSchool.ydk`), its 17
|
||||
cards in `Data/locales/en-US/cards.cdb`, their scripts and the system scripts in `Data/script.zip`, the loose
|
||||
`Expansions/script/procedure.lua` override, the en-US `bot.conf`, and one character that owns the deck
|
||||
(`Data/Characters/fixture-oldschool`, Smart brain).
|
||||
|
||||
Built by `make-fixture.py` from:
|
||||
|
||||
- the Unity repo's `Data/locales/en-US/{cards.cdb,bot.conf}`, `Data/script.zip` and
|
||||
`Data/Windbot/Decks/AI_OldSchool.ydk` at `dev` `19c6158197a0a8f0817dd0924bb9a6a987c2bfc5`;
|
||||
- `Expansions/script/procedure.lua` of the local v2 game copy (`/mnt/nvme/yugioh-legacy-v2-local/game`, never the
|
||||
live share).
|
||||
|
||||
```bash
|
||||
python3 -I tests/fixture/make-fixture.py <dir with that Data/> <a game copy's Expansions/script> tests/fixture/game
|
||||
```
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"_comment": "Test fixture: owns AI_OldSchool so its seats play the Smart brain.",
|
||||
"id": "fixture-oldschool",
|
||||
"name": "Old School",
|
||||
"decks": [
|
||||
{ "path": "AI_OldSchool", "brain": { "executor": "Smart", "difficulty": "hard", "knobs": { "aggression": 0.5 } } }
|
||||
],
|
||||
"brain": { "executor": "Lucky", "difficulty": "normal", "knobs": {} }
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#created by ...
|
||||
#main
|
||||
6631034
|
||||
6631034
|
||||
6631034
|
||||
43096270
|
||||
43096270
|
||||
43096270
|
||||
69247929
|
||||
69247929
|
||||
69247929
|
||||
77542832
|
||||
77542832
|
||||
77542832
|
||||
11091375
|
||||
11091375
|
||||
11091375
|
||||
35052053
|
||||
35052053
|
||||
35052053
|
||||
49881766
|
||||
83104731
|
||||
83104731
|
||||
30190809
|
||||
30190809
|
||||
26412047
|
||||
26412047
|
||||
26412047
|
||||
43422537
|
||||
43422537
|
||||
43422537
|
||||
53129443
|
||||
66788016
|
||||
66788016
|
||||
66788016
|
||||
72302403
|
||||
72302403
|
||||
44095762
|
||||
44095762
|
||||
44095762
|
||||
70342110
|
||||
70342110
|
||||
#extra
|
||||
!side
|
||||
@@ -0,0 +1,280 @@
|
||||
#bots list
|
||||
# !name
|
||||
# command
|
||||
# description
|
||||
# flags (avail flags: SUPPORT_MASTER_RULE_3, SUPPORT_NEW_MASTER_RULE, SUPPORT_MASTER_RULE_2020, SELECT_DECKFILE)
|
||||
|
||||
!Random Draft - Very Easy
|
||||
Random=AI_LV1
|
||||
for Beginners
|
||||
SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Random Draft - Easy
|
||||
Random=AI_LV2
|
||||
for Free Players
|
||||
SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Random Draft - Normal
|
||||
Random=AI_LV3
|
||||
for Challengers
|
||||
SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Random Draft - Classic
|
||||
Random=AI_LV4
|
||||
for hardcore Players
|
||||
SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Random Draft - Wild
|
||||
Random=AI_WILD
|
||||
CHECK THIS OUT!
|
||||
SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Random Draft - Anti-Meta
|
||||
Random=AI_ANTI_META
|
||||
for Champions
|
||||
SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Dovphin - Use your Deck
|
||||
Name=Dovphin Deck=Lucky Dialog=Ghoul.EN
|
||||
Select your Deck to let the Bot use it. The bot won't play it well.
|
||||
SELECT_DECKFILE SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Mokey Mokey
|
||||
Name='Mokey Mokey' Deck='MokeyMokey' Dialog=Mokey.EN
|
||||
Tiny fluffball, huge heart—feel the Mokey power!
|
||||
AI_LV1 SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Mokey Mokey King
|
||||
Name='Mokey Mokey King' Deck='MokeyMokeyKing' Dialog=Mokey.EN
|
||||
Bow before the fluffball king!
|
||||
AI_LV1 SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Swordsman-Dragunity
|
||||
Name='Stardust Dragon/Assault Mode' Deck=Dragunity Dialog=Swordsman.EN
|
||||
Soar with Dragunity lances and Stardust Assault!
|
||||
AI_LV2 SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Swordsman-LV8
|
||||
Name='Red Dragon Archfiend' Deck='Level VIII' Dialog=Swordsman.EN
|
||||
Level-up your blade—Synchro into Level 8 supremacy!
|
||||
AI_LV2 SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Swordsman-RANK5
|
||||
Name='Constellar Pleiades' Deck='Rank V' Dialog=Swordsman.EN
|
||||
Forge mighty Rank 5 Xyz blades!
|
||||
AI_LV2 SUPPORT_MASTER_RULE_3 SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Swordsman-Zexal Weapons
|
||||
Name='Number S39: Utopia the Lightning' Deck='Zexal Weapons' Dialog=Swordsman.EN
|
||||
Unleash Utopia’s arsenal—ZW Lightning strikes!
|
||||
AI_LV2 SUPPORT_MASTER_RULE_3 SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Rainbow
|
||||
Name='Rabidragon' Deck='Rainbow' Dialog=Cirno.EN
|
||||
A dazzling spectrum of Normal monsters!
|
||||
AI_LV2 SUPPORT_MASTER_RULE_3 SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Toadally Awesome
|
||||
Name='Toadally Awesome' Deck='Toadally Awesome' Dialog=Cirno.EN
|
||||
Croak and conquer—the pond belongs to you!
|
||||
AI_LV3 SUPPORT_MASTER_RULE_3 SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Blue-Eyes
|
||||
Name='Blue-Eyes White Dragon' Deck='Blue-Eyes' Dialog=Universal.EN
|
||||
Unleash the white lightning of legend!
|
||||
AI_LV3 SUPPORT_MASTER_RULE_3 SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Invoked Zoodiac Kaiju
|
||||
Name='Invoked Mechaba' Deck='Zoodiac' Dialog=Universal.EN
|
||||
Fuse, barrage and kaiju-slam your way to victory!
|
||||
AI_LV4 SUPPORT_MASTER_RULE_3 SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Yosenju
|
||||
Name='Yosenju Misak' Deck='Yosenju' Dialog=Universal_2.EN
|
||||
Swift strikes from wandering wind-beasts!
|
||||
AI_ANTI_META SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Qliphort
|
||||
Name='Apoqliphort Towers' Deck='Qliphort' Dialog=Universal_2.EN
|
||||
Summon the towering Qliphort colossus!
|
||||
AI_ANTI_META SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Trickstar
|
||||
Name='Trickstar Holly Angel' Deck='Trickstar' Dialog=Universal_2.EN
|
||||
Sweet smiles, cruel burn—Trickstar tempo!
|
||||
AI_LV4 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Altergeist
|
||||
Name='Altergeist Multifaker' Deck='Altergeist' Dialog=Universal_2.EN
|
||||
Warp reality with Altergeist traps!
|
||||
AI_LV4 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Labrynth
|
||||
Name='Lady Labrynth of the Silver Castle' Deck='Labrynth' Dialog=Universal_2.EN
|
||||
Enter the Labrynth and unleash fiendish furniture!
|
||||
AI_LV4 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Yubel
|
||||
Name='Spirit of Yubel' Deck='Yubel' Dialog=Universal_3.EN
|
||||
A Fiend Link build that pairs Unchained—later adding Fiendsmith—with Yubel pieces to pop your own cards for value, loop floaters, and churn Link material for steady disruption and pressure.
|
||||
AI_LV4 SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!OCG Maliss
|
||||
Name='OCG Maliss' Deck=MalissOCG Dialog=Universal_3.EN
|
||||
Full-power Maliss deck (OCG).
|
||||
AI_LV4 SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!MD Maliss
|
||||
Name='MD Maliss' Deck=Maliss Dialog=Universal_3.EN
|
||||
Full-power Maliss deck (MD).
|
||||
AI_LV4 SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Sky Striker Ace
|
||||
Name='Sky Striker Ace - Raye' Deck='SkyStriker' Dialog=Universal_3.EN
|
||||
Sky-strike with surgical spell supremacy!
|
||||
AI_LV3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Orcust
|
||||
Name='Galatea, the Orcust Automaton' Deck='Orcust' Dialog=Universal_3.EN
|
||||
Let the Orcust orchestra resound!
|
||||
AI_LV3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Salamangreat
|
||||
Name='Salamangreat Heatleo' Deck='Salamangreat' Dialog=Universal_3.EN
|
||||
Reincarnate and roar with Salamangreat flames!
|
||||
AI_LV3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Ryzeal
|
||||
Name='Ryzeal' Deck='Ryzeal' Dialog=Universal_3.EN
|
||||
Face the swirling chaos of Ryzeal!
|
||||
AI_LV4 SUPPORT_MASTER_RULE_3 SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Familiar-Possesed
|
||||
Name='Eria the Water Charmer' Deck='FamiliarPossessed' Dialog=VI-1911.EN
|
||||
Summon elemental familiars for overwhelming force!
|
||||
AI_ANTI_META SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Time Thief
|
||||
Name='Time Thief Redoer' Deck='TimeThief' Dialog=VI-1911.EN
|
||||
Steal turns and fates with Time-Thief tricks!
|
||||
AI_LV2 SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Burn Burn
|
||||
Name='Lava Golem' Deck='Burn' Dialog=Universal_4.EN
|
||||
Scorch foes with relentless burn!
|
||||
AI_LV1 SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Des Frogs
|
||||
Name='D.3.S. Frog' Deck='Frog' Dialog=Universal_4.EN
|
||||
Leap to battle with poisonous frogs!
|
||||
AI_LV1 SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Horus' Servant
|
||||
Name='Horus the Black Flame Dragon LV8' Deck='Horus' Dialog=Universal_4.EN
|
||||
Command dragons with Horus’ searing gaze!
|
||||
AI_LV1 SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Bitron-Windy
|
||||
Name='Bitron' Deck='PureWinds' Dialog=Universal_5.EN
|
||||
Whirl cyber winds at your command!
|
||||
AI_LV2 SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!TestBot1732-Cyberse
|
||||
Name='Firewall Dragon' Deck='ST1732' Dialog=Universal_5.EN
|
||||
Prototype cyber arsenal ready for battle!
|
||||
AI_LV1 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!El Shaddoll
|
||||
Name='El Shaddoll Construct' Deck='LightswornShaddoldinosour' Dialog=Universal_6.EN
|
||||
Blend Lightsworn, shadows and dinos for a primal blast!
|
||||
AI_LV3 SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Dark Magician
|
||||
Name='Dark Magician' Deck='DarkMagician' Dialog=Universal_6.EN
|
||||
Channel the arcane might of the ultimate wizard!
|
||||
AI_LV3 SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Chaos-MAX
|
||||
Name='Blue-Eyes Chaos MAX Dragon' Deck='BlueEyesMaxDragon' Dialog=Universal_6.EN
|
||||
Summon the relentless Blue-Eyes Chaos MAX!
|
||||
AI_LV3 SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!The Ghost
|
||||
Name='Phantasm Spiral Dragon' Deck='Phantasm' Dialog=Universal_6.EN
|
||||
Spectral phantasms haunt every step!
|
||||
AI_ANTI_META SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Burning Fighter
|
||||
Name='Michion, the Time Lord' Deck='ChainBurn' Dialog=Universal_6.EN
|
||||
Timeless justice through chain burn!
|
||||
AI_ANTI_META SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Meta Beater
|
||||
Name='Gren Maju Da Eiza' Deck='GrenMajuThunderBoarder' Dialog=Universal_6.EN
|
||||
Feed banished power into Gren Maju’s thunder!
|
||||
AI_ANTI_META SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Joey Wheeler - Red-Eyes Dark Dragoon
|
||||
Name='Red-Eyes Dark Dragoon' Deck='Dragun' Dialog=Smart.EN
|
||||
Red-Eyes fuses into Dragoon devastation!
|
||||
AI_LV4 SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Fiber Auroradon Brave Phenix
|
||||
Name='Baronne de Fleur' Deck='Brave' Dialog=Smart.EN
|
||||
Chaos combo with Halqifibrax, tokens and Brave!
|
||||
AI_LV4 SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Madame Verre - WitchCraft
|
||||
Name='Madame Verre' Deck='Witchcraft' Dialog=MadameVerre.EN
|
||||
Bewitching Witchcraft weaves the win!
|
||||
AI_LV4 SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Exosister Mikailis
|
||||
Name='Exosister Mikailis' Deck='Exosister' Dialog=MadameVerre.EN
|
||||
Holy sisters banish from the grave!
|
||||
AI_LV4 SUPPORT_MASTER_RULE_3 SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Ecclesia-Swordsoul
|
||||
Name='Swordsoul Grandmaster - Chixiao' Deck='Swordsoul' Dialog=Ecclesia.EN
|
||||
Strike true with radiant Swordsoul!
|
||||
AI_LV4 SUPPORT_MASTER_RULE_3 SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Ecclesia-Dogmatika
|
||||
Name='Dogmatika Fleurdelis, the Knighted' Deck='Dogmatika' Dialog=Ecclesia.EN
|
||||
Dogmatika doctrine stands unbroken!
|
||||
AI_LV4 SUPPORT_MASTER_RULE_3 SUPPORT_NEW_MASTER_RULE SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Ecclesia-Albaz
|
||||
Name='Mirrorjade the Iceblade Dragon' Deck='Albaz' Dialog=Ecclesia.EN
|
||||
Albaz forges fusions in flames and frost!
|
||||
AI_LV4 SUPPORT_MASTER_RULE_3 SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Kashtira
|
||||
Name='Kashtira Arise-Heart' Deck='Kashtira' Dialog=Universal_7.EN
|
||||
Rise with Arise-Heart and lock the field!
|
||||
AI_LV4 SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Thunder Dragon
|
||||
Name='Thunder Dragon Colossus' Deck='ThunderDragon' Dialog=Universal_7.EN
|
||||
Thunder roars with Bystial surge!
|
||||
AI_WILD SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Tearlaments
|
||||
Name='Tearlaments Rulkallos' Deck='Tearlaments' Dialog=Universal_7.EN
|
||||
Merge tears into unstoppable depths!
|
||||
AI_LV4 AI_WILD SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Zefra
|
||||
Name='Zefraath' Deck='Zefra' Dialog=Universal_7.EN
|
||||
Synchronise constellations with Zefra harmony!
|
||||
AI_LV4 SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Superheavy Samurai
|
||||
Name='Midnight Snack' Deck='SuperheavySamurai' Dialog=SuperheavySamurai.EN
|
||||
Massive defence becomes offence!
|
||||
AI_LV4 SUPPORT_MASTER_RULE_2020
|
||||
|
||||
!Apophis
|
||||
Name='Apophis' Deck=Apophis Dialog=Universal_3.EN
|
||||
Temple of the Kings Deck.
|
||||
AI_LV4 SUPPORT_MASTER_RULE_2020
|
||||
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,106 @@
|
||||
"""Builds tests/fixture/game: the smallest game root the tests can duel on.
|
||||
|
||||
python3 -I tests/fixture/make-fixture.py <source root> <expansions script dir> <out dir>
|
||||
|
||||
<source root> holds the game's Data/locales/en-US/{cards.cdb,bot.conf}, Data/script.zip and
|
||||
Data/Windbot/Decks/AI_OldSchool.ydk (the Unity repo's Data/ at the commit named in tests/fixture/README.md).
|
||||
<expansions script dir> is a game copy's Expansions/script/ (its non-card files override script.zip's).
|
||||
|
||||
It also writes Data/Characters/fixture-oldschool, a character that owns the deck.
|
||||
The cards are the deck's, plus every card id their scripts name that the database has (tokens, alias targets),
|
||||
to a fixed point. The scripts are those cards' c<id>.lua and the system files (constant, utility, procedure).
|
||||
"""
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import sqlite3
|
||||
import sys
|
||||
import zipfile
|
||||
|
||||
DECK = "AI_OldSchool"
|
||||
|
||||
# A character that owns the deck, so a seat on it gets that character's name and the Smart brain (the game's
|
||||
# path: deck -> owning character -> brain), not Dovphin.
|
||||
CHARACTER = """{
|
||||
"_comment": "Test fixture: owns AI_OldSchool so its seats play the Smart brain.",
|
||||
"id": "fixture-oldschool",
|
||||
"name": "Old School",
|
||||
"decks": [
|
||||
{ "path": "AI_OldSchool", "brain": { "executor": "Smart", "difficulty": "hard", "knobs": { "aggression": 0.5 } } }
|
||||
],
|
||||
"brain": { "executor": "Lucky", "difficulty": "normal", "knobs": {} }
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def deck_ids(path):
|
||||
ids = []
|
||||
for line in open(path, encoding="utf-8-sig"):
|
||||
line = line.strip()
|
||||
if line.isdigit():
|
||||
ids.append(int(line))
|
||||
return ids
|
||||
|
||||
|
||||
def main(src, exp_script, out):
|
||||
cdb = os.path.join(src, "Data/locales/en-US/cards.cdb")
|
||||
scripts = zipfile.ZipFile(os.path.join(src, "Data/script.zip"))
|
||||
names = set(scripts.namelist())
|
||||
db = sqlite3.connect("file:" + cdb + "?mode=ro", uri=True)
|
||||
known = {row[0] for row in db.execute("SELECT id FROM datas")}
|
||||
|
||||
def script_of(code):
|
||||
name = "script/c%d.lua" % code
|
||||
return scripts.read(name).decode("utf-8", "replace") if name in names else ""
|
||||
|
||||
want = set(deck_ids(os.path.join(src, "Data/Windbot/Decks", DECK + ".ydk")))
|
||||
todo = list(want)
|
||||
while todo:
|
||||
code = todo.pop()
|
||||
refs = {int(n) for n in re.findall(r"\b\d{5,9}\b", script_of(code))}
|
||||
alias = db.execute("SELECT alias FROM datas WHERE id=?", (code,)).fetchone()
|
||||
if alias and alias[0]:
|
||||
refs.add(alias[0])
|
||||
for ref in refs & known - want:
|
||||
want.add(ref)
|
||||
todo.append(ref)
|
||||
|
||||
if os.path.exists(out):
|
||||
shutil.rmtree(out)
|
||||
os.makedirs(os.path.join(out, "Data/locales/en-US"))
|
||||
os.makedirs(os.path.join(out, "Data/Windbot/Decks"))
|
||||
os.makedirs(os.path.join(out, "Expansions/script"))
|
||||
os.makedirs(os.path.join(out, "Data/Characters/fixture-oldschool"))
|
||||
with open(os.path.join(out, "Data/Characters/fixture-oldschool/character.json"), "w", newline="\n") as f:
|
||||
f.write(CHARACTER)
|
||||
|
||||
sub = sqlite3.connect(os.path.join(out, "Data/locales/en-US/cards.cdb"))
|
||||
for (sql,) in db.execute("SELECT sql FROM sqlite_master WHERE type='table' AND name IN ('datas','texts')"):
|
||||
sub.execute(sql)
|
||||
for table in ("datas", "texts"):
|
||||
cols = len(db.execute("SELECT * FROM %s LIMIT 1" % table).description)
|
||||
rows = db.execute("SELECT * FROM %s WHERE id IN (%s) ORDER BY id" % (table, ",".join(map(str, sorted(want))))).fetchall()
|
||||
sub.executemany("INSERT INTO %s VALUES (%s)" % (table, ",".join("?" * cols)), rows)
|
||||
sub.commit()
|
||||
sub.execute("VACUUM")
|
||||
sub.close()
|
||||
|
||||
keep = sorted(n for n in names if n.startswith("script/") and not re.match(r"script/c\d+\.lua$", n) and not n.endswith("/"))
|
||||
keep += sorted("script/c%d.lua" % c for c in want if "script/c%d.lua" % c in names)
|
||||
with zipfile.ZipFile(os.path.join(out, "Data/script.zip"), "w", zipfile.ZIP_DEFLATED) as z:
|
||||
for n in keep:
|
||||
info = zipfile.ZipInfo(n, date_time=(2026, 1, 1, 0, 0, 0))
|
||||
info.compress_type = zipfile.ZIP_DEFLATED
|
||||
z.writestr(info, scripts.read(n))
|
||||
|
||||
for name in sorted(os.listdir(exp_script)):
|
||||
if name.endswith(".lua") and not re.match(r"c\d+\.lua$", name):
|
||||
shutil.copyfile(os.path.join(exp_script, name), os.path.join(out, "Expansions/script", name))
|
||||
|
||||
shutil.copyfile(os.path.join(src, "Data/locales/en-US/bot.conf"), os.path.join(out, "Data/locales/en-US/bot.conf"))
|
||||
shutil.copyfile(os.path.join(src, "Data/Windbot/Decks", DECK + ".ydk"), os.path.join(out, "Data/Windbot/Decks", DECK + ".ydk"))
|
||||
print("%d cards, %d scripts -> %s" % (len(want), len(keep), out))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(*sys.argv[1:4])
|
||||
Reference in new issue
Block a user