add learning after episode
This commit is contained in:
+22
-13
@@ -25,8 +25,8 @@ 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)
|
||||
players = player_provider.choose()
|
||||
state = create_empty_state()
|
||||
players = player_provider.choose(state)
|
||||
move = 1
|
||||
run = True
|
||||
other_player = players[-1]
|
||||
@@ -43,14 +43,14 @@ def play(player_provider: PlayerProvider, k_max=10000, with_debug=False):
|
||||
if not has_moved:
|
||||
if with_debug:
|
||||
print(f"{player.mark}: No more moves")
|
||||
player.end_game(0.0)
|
||||
other_player.end_game(0.0)
|
||||
player.end_game(state, 0.0)
|
||||
other_player.end_game(state, 0.0)
|
||||
run = False
|
||||
if player.has_won(state):
|
||||
if with_debug:
|
||||
print(f"{player.mark}: Has won the game")
|
||||
player.end_game(1.0)
|
||||
other_player.end_game(0.0)
|
||||
player.end_game(state, 1.0)
|
||||
other_player.end_game(state, 0.0)
|
||||
run = False
|
||||
|
||||
other_player = player
|
||||
@@ -60,21 +60,30 @@ def play(player_provider: PlayerProvider, k_max=10000, with_debug=False):
|
||||
move += 1
|
||||
|
||||
|
||||
with open("values_x.json", "r") as fp:
|
||||
x_values = json.load(fp)
|
||||
|
||||
with open("values_o.json", "r") as fp:
|
||||
o_values = json.load(fp)
|
||||
|
||||
do_training = 1
|
||||
do_human_player = 1
|
||||
do_human_player = 0
|
||||
do_load_values = 1
|
||||
|
||||
if do_load_values:
|
||||
try:
|
||||
with open("values_x.json", "r") as fp:
|
||||
x_values = json.load(fp)
|
||||
|
||||
with open("values_o.json", "r") as fp:
|
||||
o_values = json.load(fp)
|
||||
except Exception:
|
||||
x_values = {}
|
||||
o_values = {}
|
||||
else:
|
||||
x_values = {}
|
||||
o_values = {}
|
||||
|
||||
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(PlayerProvider(p_mx, p_mo), 10000, False)
|
||||
play(PlayerProvider(p_mx, p_mo), 5000, True)
|
||||
|
||||
# Values after training
|
||||
# Convert and write JSON object to file
|
||||
|
||||
Reference in New Issue
Block a user