files-game/tests/smoke.gd
2026-10-01 17:22:18 -04:00

40 lines
1.3 KiB
GDScript

extends SceneTree
## Plays random-vs-random games with every Set 1 card and checks the rule invariants after every
## action. Quicker than conformance for catching script errors; conformance checks the results.
##
## godot --headless --script res://tests/smoke.gd -- [--games N] [--seed N] [--rule K=V]...
func _init() -> void:
var games := 20
var first := 1
var rules := Rules.defaults()
var args := OS.get_cmdline_user_args()
var i := 0
while i < args.size():
match args[i]:
"--games":
i += 1
games = int(args[i])
"--seed":
i += 1
first = int(args[i])
"--rule":
i += 1
rules = Rules.with_rule(rules, args[i])
i += 1
var pool := Cards.load_cards()
for w in CardScripts.stale_scripts(pool):
print("warning: %s" % w)
var started := Time.get_ticks_msec()
var failed := 0
for seed in range(first, first + games):
Util.errors.clear()
var random: Callable = Play.bots().random
var s = Play.play_game({"pool": pool, "bots": [random, random], "seed": seed, "rules": rules, "check": true})
if s == null or not Util.errors.is_empty():
failed += 1
print("seed %d: %s" % [seed, "; ".join(Util.errors)])
var secs := (Time.get_ticks_msec() - started) / 1000.0
print("smoke: %d/%d games ran clean (%.1fs)" % [games - failed, games, secs])
quit(0 if failed == 0 else 1)