@@ -33,33 +33,45 @@ def simulate_day(game_state: GameState):
3333 print (f"🏁 Game Over — { game_state .game_result .replace ('_' , ' ' ).title ()} " )
3434 game_state .day += 1
3535
36- def main ():
37- parser = argparse .ArgumentParser (description = "Run Tragedy Looper simulation." )
38- parser .add_argument ("script_name" , help = "Name of the script YAML file (without extension)" )
39- parser .add_argument ("actions_file" , help = "Name of the actions YAML file (without extension)" )
40-
41- args = parser .parse_args ()
42-
43- # Assuming your YAML files live in a folder like 'scripts/' and have a '.yaml' extension
44- script_path = f"scripts/{ args .script_name } /script.yaml"
45- actions_path = f"scripts/{ args .script_name } /{ args .actions_file } .yaml"
46-
36+ def run_full_simulation (script_path : str , actions_path : str ) -> GameState :
37+ """
38+ Runs a full game simulation and returns the final state.
39+ This function is designed to be testable.
40+ """
4741 game_state = create_starting_game_state (script_path , actions_path )
42+
4843 while game_state .game_result is None :
4944 if game_state .day > game_state .days_per_loop :
50- # We've finished a loop. Time to check for victory and reset.
51- check_victory (game_state ) # Final check at loop end
45+ check_victory (game_state )
5246 if game_state .game_result is None :
5347 if game_state .loop_count >= game_state .max_loops :
54- # We've run out of loops, mastermind wins.
55- print ("⏰ The protagonists have run out of time!" )
5648 game_state .game_result = "mastermind_win"
5749 else :
58- # Reset for the next loop
5950 reset_for_new_loop (game_state )
6051
6152 if game_state .game_result is None :
6253 simulate_day (game_state )
54+
55+ # After the loop, do one final check on the very last day's state
56+ check_victory (game_state )
57+ return game_state
58+
59+ def main ():
60+ parser = argparse .ArgumentParser (description = "Run Tragedy Looper simulation." )
61+ parser .add_argument ("script_name" , help = "Name of the script YAML file (without extension)" )
62+ parser .add_argument ("actions_file" , help = "Name of the actions YAML file (without extension)" )
63+
64+ args = parser .parse_args ()
65+
66+ # Assuming your YAML files live in a folder like 'scripts/' and have a '.yaml' extension
67+ script_path = f"scripts/{ args .script_name } /script.yaml"
68+ actions_path = f"scripts/{ args .script_name } /{ args .actions_file } .yaml"
69+
70+ final_state = run_full_simulation (script_path , actions_path )
71+ print ("\n --- Final Results ---" )
72+ if final_state .game_result :
73+ print (f"🏁 Game Over — { final_state .game_result .replace ('_' , ' ' ).title ()} " )
74+ final_state .print_characters ()
6375
6476
6577if __name__ == "__main__" :
0 commit comments