()
| 303 | |
| 304 | |
| 305 | def main() -> None: |
| 306 | parser = argparse.ArgumentParser() |
| 307 | parser.add_argument("--agent", action="append", type=parse_agent_arg, required=True) |
| 308 | parser.add_argument("--episodes", type=int, default=3) |
| 309 | parser.add_argument("--steps", type=int, default=30) |
| 310 | parser.add_argument("--drones", type=int, default=18) |
| 311 | parser.add_argument("--decision-timeout", type=float, default=3.0) |
| 312 | parser.add_argument("--output", required=True) |
| 313 | args = parser.parse_args() |
| 314 | |
| 315 | if args.episodes < 1: |
| 316 | parser.error("--episodes must be at least 1") |
| 317 | if args.steps < 1: |
| 318 | parser.error("--steps must be at least 1") |
| 319 | if args.drones < 1: |
| 320 | parser.error("--drones must be at least 1") |
| 321 | if args.decision_timeout <= 0: |
| 322 | parser.error("--decision-timeout must be positive") |
| 323 | |
| 324 | agent_paths = dict(args.agent) |
| 325 | totals = {name: 0.0 for name in agent_paths} |
| 326 | details = [] |
| 327 | |
| 328 | for episode_idx in range(args.episodes): |
| 329 | for player_name, policy_path in agent_paths.items(): |
| 330 | result = evaluate_player( |
| 331 | player_name, |
| 332 | policy_path, |
| 333 | episode_idx=episode_idx, |
| 334 | steps=args.steps, |
| 335 | drones=args.drones, |
| 336 | decision_timeout=args.decision_timeout, |
| 337 | ) |
| 338 | totals[player_name] += result["score"] |
| 339 | details.append(result) |
| 340 | |
| 341 | averages = {player: score / args.episodes for player, score in totals.items()} |
| 342 | output = { |
| 343 | "average_scores": averages, |
| 344 | "total_scores": totals, |
| 345 | "episodes": args.episodes, |
| 346 | "details": [json.dumps(item, sort_keys=True) for item in details], |
| 347 | } |
| 348 | Path(args.output).parent.mkdir(parents=True, exist_ok=True) |
| 349 | Path(args.output).write_text(json.dumps(output, indent=2, sort_keys=True)) |
| 350 | |
| 351 | |
| 352 | if __name__ == "__main__": |
no test coverage detected