- added reward sum and reward mean

This commit is contained in:
2024-06-13 08:43:08 +02:00
parent c50553c94a
commit f70cf1fc1e
2 changed files with 41 additions and 22 deletions
+21 -15
View File
@@ -21,36 +21,42 @@ def play(player_provider: PlayerProvider, k_max=10000, with_debug=False):
run = True
other_player = players[-1]
while run:
for player in players:
do_stop = False
this_reward = 0
other_reward = 0
for this_player in players:
if with_debug:
print(f"---------------------------------------------------")
print(f"- Game {k:06d}, Move {move} -----------------------------")
print(f"---------------------------------------------------")
last_state = state
state, has_moved = player.move(state)
state, has_moved = this_player.move(state)
if with_debug:
print(to_state_string(last_state, state))
if not has_moved:
player.end_game(state, 0.0)
other_player.end_game(state, 0.0)
run = False
this_reward = 0
other_reward = 0
do_stop = True
if with_debug:
print(f"{player.mark}: No more moves")
if player.has_won(state):
player.end_game(state, 1.0)
other_player.end_game(state, 0.0)
run = False
print(f"{this_player.mark}: No more moves")
if this_player.has_won(state):
this_reward = 1
other_reward = 0
do_stop = True
if with_debug:
print(f"{player.mark}: Has won the game")
print(f"{this_player.mark}: Has won the game")
other_player = player
if not run:
if do_stop:
this_player.end_game(state, this_reward)
other_player.end_game(state, other_reward)
run = False
break
other_player = this_player
move += 1
do_training = 1
do_training = 0
do_human_player = 0
do_load_values = 1
@@ -72,7 +78,7 @@ 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
K = 5
N = 1000
if do_training:
for k in range(0, K):