From 7edfa627d03955386e5c12e84515470df15f8657 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Tue, 11 Jun 2024 21:49:49 +0200 Subject: [PATCH] Changed training to update values-file during training --- tic_tac_toe.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/tic_tac_toe.py b/tic_tac_toe.py index b32e542..3054243 100644 --- a/tic_tac_toe.py +++ b/tic_tac_toe.py @@ -12,19 +12,9 @@ REPORT_INTERVAL = 1000 report_counter = REPORT_INTERVAL -def report(k): - global report_counter - if report_counter > 0: - report_counter -= 1 - else: - report_counter = REPORT_INTERVAL-1 - print(f"Iteration: {k:8d}") - - def play(player_provider: PlayerProvider, k_max=10000, with_debug=False): player_provider.set_debug(with_debug) for k in range(0, k_max): - report(k) state = create_empty_state() players = player_provider.choose(state) move = 1 @@ -82,16 +72,21 @@ p_hx = HumanPlayer(mark='X', name="Jens") p_mx = MachinePlayer(mark='X', params=MachinePlayer.Params(p_explore=0.1, alpha=0.1), values=x_values) p_mo = MachinePlayer(mark='O', params=MachinePlayer.Params(p_explore=0.1, alpha=0.1), values=o_values) +K = 50 +N = 1000 if do_training: - play(PlayerProvider(p_mx, p_mo), 5000, False) + for k in range(0, K): + play(PlayerProvider(p_mx, p_mo), N, False) - # Values after training - # Convert and write JSON object to file - with open("values_x.json", "w") as fp: - json.dump(p_mx.values, fp, indent=0) + # Values after training + # Convert and write JSON object to file + with open("values_x.json", "w") as fp: + json.dump(p_mx.values, fp, indent=0) - with open("values_o.json", "w") as fp: - json.dump(p_mo.values, fp, indent=0) + with open("values_o.json", "w") as fp: + json.dump(p_mo.values, fp, indent=0) + + print(f"Iteration: {k*N:8d}") if do_human_player: pp = PlayerProvider(p_hx, p_mo)