Changed training to update values-file during training

This commit is contained in:
2024-06-11 21:49:49 +02:00
parent 7a1156125c
commit 7edfa627d0
+12 -17
View File
@@ -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)