Skip to content

Commit 04fb4f4

Browse files
committed
count sum of rewards per episode, not just the last one
1 parent 4c19a6d commit 04fb4f4

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

agents/attackers/random/random_agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def play_game(self, observation, num_episodes=1):
4242
observation = self.request_game_reset()
4343
self._logger.info(f"Final results for {self.__class__.__name__} after {num_episodes} episodes: {np.mean(returns)}±{np.std(returns)}")
4444
# This will be the last observation played before the reset
45-
return (last_observation, num_steps)
45+
return (last_observation, np.mean(returns), num_steps)
4646

4747
def select_action(self, observation:Observation)->Action:
4848
valid_actions = generate_valid_actions(observation.state)
@@ -115,10 +115,10 @@ def select_action(self, observation:Observation)->Action:
115115
print(f'Starting the testing for episode {episode}')
116116

117117
# Play the game for one episode
118-
observation, num_steps = agent.play_game(observation, 1)
118+
observation, avg_return, num_steps = agent.play_game(observation, 1)
119119

120120
state = observation.state
121-
reward = observation.reward
121+
reward = avg_return
122122
end = observation.end
123123
info = observation.info
124124

agents/attackers/random/whitebox_random_agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def play_game(self, observation, num_episodes=1):
4545
observation = self.request_game_reset()
4646
self._logger.info(f"Final results for {self.__class__.__name__} after {num_episodes} episodes: {np.mean(returns)}±{np.std(returns)}")
4747
# This will be the last observation played before the reset
48-
return (last_observation, num_steps)
48+
return (last_observation, np.mean(returns), num_steps)
4949

5050
def select_action(self, observation:Observation)->Action:
5151
# Get the valid action mask (boolean array) for the current state using the parent class method
@@ -126,10 +126,10 @@ def select_action(self, observation:Observation)->Action:
126126
print(f'Starting the testing for episode {episode}')
127127

128128
# Play the game for one episode
129-
observation, num_steps = agent.play_game(observation, 1)
129+
observation, avg_return, num_steps = agent.play_game(observation, 1)
130130

131131
state = observation.state
132-
reward = observation.reward
132+
reward = avg_return
133133
end = observation.end
134134
info = observation.info
135135

0 commit comments

Comments
 (0)