## A12: plays the tutorial from start to end with its scripted player (TutorialPilot), ## through a real ClientSession on its offline server, as fast as it will go, on each ## seed asked for. Each seed must reach the last step within the time limit, with no ## script or engine error. ## ## tools/godot.sh --script res://tools/tutorial_check.gd -- [--seeds=N] [--first=N] ## ## Prints one JSON line per seed (the seconds each step took, in game time) and a ## verdict. Exits 1 on any failure. extends SceneTree ## Game seconds a seed may take before it counts as stuck. const LIMIT_SECONDS: float = 600.0 func _init() -> void: var seeds: int = 5 var first: int = 1 for arg: String in OS.get_cmdline_user_args(): if arg.begins_with("--seeds=") and arg.trim_prefix("--seeds=").is_valid_int(): seeds = maxi(arg.trim_prefix("--seeds=").to_int(), 1) elif arg.begins_with("--first=") and arg.trim_prefix("--first=").is_valid_int(): first = arg.trim_prefix("--first=").to_int() else: print("tutorial-check FAIL: unknown argument '%s'" % arg) quit(2) return var errors: ErrorCounter = ErrorCounter.new() OS.add_logger(errors) var problems: Array[String] = [] for seed_value: int in range(first, first + seeds): var result: Dictionary = play(seed_value, LIMIT_SECONDS) print(JSON.stringify(result)) if not bool(result["finished"]): problems.append("seed %d stopped at '%s'" % [seed_value, result["step"]]) OS.remove_logger(errors) if errors.count() > 0: problems.append("%d script or engine errors, first: %s" % [errors.count(), errors.first()]) for problem: String in problems: print("tutorial-check FAIL: %s" % problem) if problems.is_empty(): print("tutorial-check: ok (%d seeds played from the ship to the end)" % seeds) quit(0 if problems.is_empty() else 1) ## Plays one seed's tutorial with the pilot, a tick a frame, for up to `limit` game ## seconds. Returns {"seed", "finished", "step", "seconds", "steps": {name: seconds}}. static func play(seed_value: int, limit: float) -> Dictionary: var session: ClientSession = ClientSession.new() session.input.autoplay = true session.play_tutorial(seed_value) var delta: float = 1.0 / Tuning.TICK_RATE_HZ var frames: int = 0 var most: int = roundi(limit * Tuning.TICK_RATE_HZ) while frames < most and not session.tutorial.finished(): session.pump(delta) frames += 1 var steps: Dictionary = {} for index: int in Tutorial.DONE: steps[Tutorial.STEP_NAMES[index]] = snappedf(session.tutorial.step_seconds[index], 0.1) var result: Dictionary = { "seed": seed_value, "finished": session.tutorial.finished(), "step": session.tutorial.step_name(), "seconds": snappedf(float(frames) * delta, 0.1), "steps": steps, } session.free() return result