Refactored
This commit is contained in:
+21
-14
@@ -1,5 +1,5 @@
|
||||
import numpy as np
|
||||
from helper import create_empty_state, to_state_string
|
||||
from state import create_empty_state, to_state_string
|
||||
from machine_player import MachinePlayer
|
||||
from human_player import HumanPlayer
|
||||
from player_provider import PlayerProvider
|
||||
@@ -66,21 +66,28 @@ with open("values_x.json", "r") as fp:
|
||||
with open("values_o.json", "r") as fp:
|
||||
o_values = json.load(fp)
|
||||
|
||||
#px = MachinePlayer(mark='X', params=MachinePlayer.Params(p_exp=0.2, alpha=0.1), values=x_values)
|
||||
px = HumanPlayer(mark='X', name="Jens")
|
||||
po = MachinePlayer(mark='O', params=MachinePlayer.Params(p_exp=0.2, alpha=0.1), values=o_values)
|
||||
|
||||
player_provider = PlayerProvider(px, po)
|
||||
|
||||
do_training = 1
|
||||
do_human_player = 1
|
||||
|
||||
p_hx = HumanPlayer(mark='X', name="Jens")
|
||||
p_mx = MachinePlayer(mark='X', params=MachinePlayer.Params(p_explore=0.2, alpha=0.1), values=x_values)
|
||||
p_mo = MachinePlayer(mark='O', params=MachinePlayer.Params(p_explore=0.2, alpha=0.1), values=o_values)
|
||||
|
||||
if do_training:
|
||||
play(player_provider, 10000, True)
|
||||
play(PlayerProvider(p_mx, p_mo), 10000, False)
|
||||
|
||||
play(player_provider, 10, True)
|
||||
# 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)
|
||||
|
||||
# Convert and write JSON object to file
|
||||
with open("values_x.json", "w") as fp:
|
||||
json.dump(x_values, fp, indent=0)
|
||||
with open("values_o.json", "w") as fp:
|
||||
json.dump(p_mo.values, fp, indent=0)
|
||||
|
||||
if do_human_player:
|
||||
pp = PlayerProvider(p_hx, p_mo)
|
||||
else:
|
||||
pp = PlayerProvider(p_mx, p_mo)
|
||||
|
||||
play(pp, 10, True)
|
||||
|
||||
with open("values_o.json", "w") as fp:
|
||||
json.dump(o_values, fp, indent=0)
|
||||
|
||||
Reference in New Issue
Block a user