@@ -452,6 +452,43 @@ def _receive_user_inputs(self,
452452 for user_inputs in agent_user_inputs .values ():
453453 user_inputs += new_user_inputs
454454
455+ @classmethod
456+ def override_args_with_replay (cls ,
457+ args : argparse .Namespace , base_agent_infos : dict [int , pacai .core .agentinfo .AgentInfo ]) -> None :
458+ """
459+ Override the args with the settings from the replay in the args.
460+ Children may extend this for additional functionality.
461+ """
462+
463+ logging .info ("Loading replay from '%s'." , args .replay_path )
464+ replay_info = typing .cast (GameResult , edq .util .json .load_object_path (args .replay_path , GameResult ))
465+
466+ # Overrides from the replay info.
467+ args .board = replay_info .game_info .board_source
468+ args .seed = replay_info .game_info .seed
469+
470+ # Special settings for replays.
471+ args .num_games = 1
472+ args .num_training = 0
473+ args .max_turns = len (replay_info .history )
474+
475+ # Script the moves for each agent based on the replay's history.
476+ scripted_actions : dict [int , list [pacai .core .action .Action ]] = {}
477+ for item in replay_info .history :
478+ if (item .agent_index not in scripted_actions ):
479+ scripted_actions [item .agent_index ] = []
480+
481+ scripted_actions [item .agent_index ].append (item .get_action ())
482+
483+ base_agent_infos .clear ()
484+
485+ for (agent_index , actions ) in scripted_actions .items ():
486+ base_agent_infos [agent_index ] = pacai .core .agentinfo .AgentInfo (
487+ name = pacai .util .alias .AGENT_SCRIPTED .short ,
488+ move_delay = replay_info .game_info .agent_infos [agent_index ].move_delay ,
489+ actions = actions ,
490+ )
491+
455492def set_cli_args (parser : argparse .ArgumentParser , default_board : str | None = None ) -> argparse .ArgumentParser :
456493 """
457494 Set common CLI arguments.
@@ -553,7 +590,7 @@ def init_from_args(
553590 # then all the core arguments are loaded differently (directly from the file).
554591 # Use the replay file to override all the current options.
555592 if (args .replay_path is not None ):
556- _override_args_with_replay (args , base_agent_infos )
593+ game_class . override_args_with_replay (args , base_agent_infos )
557594 remove_agent_indexes = []
558595
559596 if (args .board is None ):
@@ -635,40 +672,6 @@ def init_from_args(
635672
636673 return args
637674
638- def _override_args_with_replay (args : argparse .Namespace , base_agent_infos : dict [int , pacai .core .agentinfo .AgentInfo ]) -> None :
639- """
640- Override the args with the settings from the replay in the args.
641- """
642-
643- logging .info ("Loading replay from '%s'." , args .replay_path )
644- replay_info = typing .cast (GameResult , edq .util .json .load_object_path (args .replay_path , GameResult ))
645-
646- # Overrides from the replay info.
647- args .board = replay_info .game_info .board_source
648- args .seed = replay_info .game_info .seed
649-
650- # Special settings for replays.
651- args .num_games = 1
652- args .num_training = 0
653- args .max_turns = len (replay_info .history )
654-
655- # Script the moves for each agent based on the replay's history.
656- scripted_actions : dict [int , list [pacai .core .action .Action ]] = {}
657- for item in replay_info .history :
658- if (item .agent_index not in scripted_actions ):
659- scripted_actions [item .agent_index ] = []
660-
661- scripted_actions [item .agent_index ].append (item .get_action ())
662-
663- base_agent_infos .clear ()
664-
665- for (agent_index , actions ) in scripted_actions .items ():
666- base_agent_infos [agent_index ] = pacai .core .agentinfo .AgentInfo (
667- name = pacai .util .alias .AGENT_SCRIPTED .short ,
668- move_delay = replay_info .game_info .agent_infos [agent_index ].move_delay ,
669- actions = actions ,
670- )
671-
672675def _parse_agent_infos (
673676 agent_indexes : list [int ],
674677 raw_args : list [str ],
0 commit comments