Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """Interactive text CLI for human play-testing.""" | |
| import argparse | |
| import sys | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).parent.parent)) | |
| from turnabout.envs.text_env import TextCourtEnv | |
| def main(): | |
| parser = argparse.ArgumentParser(description="Play a Turnabout case interactively") | |
| parser.add_argument( | |
| "case", | |
| nargs="?", | |
| default=str(Path(__file__).parent.parent / "turnabout" / "cases" / "stolen_prototype.json"), | |
| help="Path to case JSON file", | |
| ) | |
| parser.add_argument( | |
| "-d", "--difficulty", | |
| choices=["easy", "hard"], | |
| default=None, | |
| help="Override case difficulty", | |
| ) | |
| args = parser.parse_args() | |
| env = TextCourtEnv(case_path=args.case, difficulty=args.difficulty) | |
| print("=" * 60) | |
| print(" TURNABOUT - Interactive Court Game") | |
| print("=" * 60) | |
| print() | |
| print(env.system_prompt) | |
| print() | |
| print("Type 'quit' to exit, 'help' for commands, 'status' for evidence.") | |
| print("=" * 60) | |
| print() | |
| obs = env.reset() | |
| print(obs) | |
| while True: | |
| print() | |
| try: | |
| action = input(">> ").strip() | |
| except (EOFError, KeyboardInterrupt): | |
| print("\nGoodbye!") | |
| break | |
| if not action: | |
| continue | |
| if action.lower() == "quit": | |
| print("Goodbye!") | |
| break | |
| if action.lower() == "help": | |
| print(env.system_prompt) | |
| continue | |
| if action.lower() == "status": | |
| print(env.render()) | |
| continue | |
| obs, reward, done, info = env.step(action) | |
| print(obs) | |
| if reward != 0: | |
| print(f" [Reward: {reward:+.2f}]") | |
| if done: | |
| print() | |
| print("=" * 60) | |
| metrics = env.get_metrics() | |
| print(f" Result: {'WON' if metrics.won else 'LOST'}") | |
| print(f" Steps: {metrics.total_steps}") | |
| print(f" Contradiction Accuracy: {metrics.contradiction_accuracy:.1%}") | |
| print(f" Evidence Coverage: {metrics.evidence_coverage:.1%}") | |
| print(f" Composite Score: {metrics.composite_score:.3f}") | |
| print("=" * 60) | |
| break | |
| if __name__ == "__main__": | |
| main() | |