- bugfix not rewarding properly

- bugfix not set value properly after learn
This commit is contained in:
2024-06-11 21:15:55 +02:00
parent e8d07f9d84
commit 7a1156125c
2 changed files with 8 additions and 8 deletions
+1 -1
View File
@@ -60,7 +60,7 @@ class MachinePlayer(APlayer):
rev_hist = list(reversed(self.episode_history))
for hist in rev_hist:
d = self.calc_value(hist['state'], hist['next_state'])
if hist['is_exp']:
if not hist['is_exp']:
self.set_value(hist['state'], d)
def calc_value(self, state: np.array, next_state: np.array):
+7 -7
View File
@@ -41,17 +41,17 @@ def play(player_provider: PlayerProvider, k_max=10000, with_debug=False):
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
if with_debug:
print(f"{player.mark}: No more moves")
player.end_game(state, 0.0)
other_player.end_game(state, 0.0)
run = False
if player.has_won(state):
player.end_game(state, 1.0)
other_player.end_game(state, 0.0)
run = False
if with_debug:
print(f"{player.mark}: Has won the game")
player.end_game(state, 1.0)
other_player.end_game(state, 0.0)
run = False
other_player = player
if not run:
@@ -83,7 +83,7 @@ p_mx = MachinePlayer(mark='X', params=MachinePlayer.Params(p_explore=0.1, alpha=
p_mo = MachinePlayer(mark='O', params=MachinePlayer.Params(p_explore=0.1, alpha=0.1), values=o_values)
if do_training:
play(PlayerProvider(p_mx, p_mo), 50000, False)
play(PlayerProvider(p_mx, p_mo), 5000, False)
# Values after training
# Convert and write JSON object to file