Spaces:
Runtime error
Runtime error
| """proteus.cli.commands.play — the ``play`` subcommand (human via stdin).""" | |
| from __future__ import annotations | |
| import argparse | |
| import sys | |
| from proteus.game.agents import HumanAgent | |
| from proteus.game.engine.difficulty import Difficulty | |
| from proteus.game.scenarios.base import list_scenarios | |
| from proteus.game.runtime import SessionRunner, append_trace | |
| from proteus.cli.commands.run import _auto_gif | |
| def _cmd_play(args: argparse.Namespace) -> int: | |
| if args.scenario not in list_scenarios(): | |
| print( | |
| f"Unknown scenario {args.scenario!r}. " | |
| f"Available scenarios: {', '.join(list_scenarios())}.", | |
| file=sys.stderr, | |
| ) | |
| return 2 | |
| agent = HumanAgent() | |
| runner = SessionRunner( | |
| args.scenario, | |
| agent, | |
| difficulty=Difficulty(args.difficulty), | |
| seed=args.seed, | |
| play_turns=args.play_turns, | |
| use_probe=args.probe, | |
| ) | |
| try: | |
| trace = runner.run() | |
| except EOFError: | |
| print("stdin closed before the session finished.", file=sys.stderr) | |
| return 2 | |
| accuracy = trace.metrics["motive_reading_accuracy"] | |
| print( | |
| f"{trace.scenario} seed={trace.seed} {trace.difficulty} " | |
| f"model={trace.model} -> {trace.outcome} " | |
| f"| motive_reading_accuracy={accuracy:.1f}% " | |
| f"| reactivity_index={trace.metrics['reactivity_index']:.1f}%" | |
| ) | |
| if args.out: | |
| written = append_trace(trace, args.out) | |
| print(f"trace appended to {written}") | |
| _auto_gif(args.out, args.no_gif) | |
| return 0 | |