- bugfix not rewarding properly
- bugfix not set value properly after learn
This commit is contained in:
+1
-1
@@ -60,7 +60,7 @@ class MachinePlayer(APlayer):
|
|||||||
rev_hist = list(reversed(self.episode_history))
|
rev_hist = list(reversed(self.episode_history))
|
||||||
for hist in rev_hist:
|
for hist in rev_hist:
|
||||||
d = self.calc_value(hist['state'], hist['next_state'])
|
d = self.calc_value(hist['state'], hist['next_state'])
|
||||||
if hist['is_exp']:
|
if not hist['is_exp']:
|
||||||
self.set_value(hist['state'], d)
|
self.set_value(hist['state'], d)
|
||||||
|
|
||||||
def calc_value(self, state: np.array, next_state: np.array):
|
def calc_value(self, state: np.array, next_state: np.array):
|
||||||
|
|||||||
+5
-5
@@ -41,17 +41,17 @@ def play(player_provider: PlayerProvider, k_max=10000, with_debug=False):
|
|||||||
if with_debug:
|
if with_debug:
|
||||||
print(to_state_string(last_state, state))
|
print(to_state_string(last_state, state))
|
||||||
if not has_moved:
|
if not has_moved:
|
||||||
if with_debug:
|
|
||||||
print(f"{player.mark}: No more moves")
|
|
||||||
player.end_game(state, 0.0)
|
player.end_game(state, 0.0)
|
||||||
other_player.end_game(state, 0.0)
|
other_player.end_game(state, 0.0)
|
||||||
run = False
|
run = False
|
||||||
if player.has_won(state):
|
|
||||||
if with_debug:
|
if with_debug:
|
||||||
print(f"{player.mark}: Has won the game")
|
print(f"{player.mark}: No more moves")
|
||||||
|
if player.has_won(state):
|
||||||
player.end_game(state, 1.0)
|
player.end_game(state, 1.0)
|
||||||
other_player.end_game(state, 0.0)
|
other_player.end_game(state, 0.0)
|
||||||
run = False
|
run = False
|
||||||
|
if with_debug:
|
||||||
|
print(f"{player.mark}: Has won the game")
|
||||||
|
|
||||||
other_player = player
|
other_player = player
|
||||||
if not run:
|
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)
|
p_mo = MachinePlayer(mark='O', params=MachinePlayer.Params(p_explore=0.1, alpha=0.1), values=o_values)
|
||||||
|
|
||||||
if do_training:
|
if do_training:
|
||||||
play(PlayerProvider(p_mx, p_mo), 50000, False)
|
play(PlayerProvider(p_mx, p_mo), 5000, False)
|
||||||
|
|
||||||
# Values after training
|
# Values after training
|
||||||
# Convert and write JSON object to file
|
# Convert and write JSON object to file
|
||||||
|
|||||||
Reference in New Issue
Block a user