This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gym | |
from stable_baselines import PPO1 | |
from stable_baselines.common.policies import MlpPolicy | |
from stable_baselines.common.callbacks import EvalCallback | |
env = gym.make('Pendulum-v0') | |
model = PPO1(MlpPolicy, env) | |
# Separate evaluation env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SelfPlayEnv(env): | |
# ... | |
def reset(self): | |
super(SelfPlayEnv, self).reset() | |
self.setup_opponents() | |
if self.current_player_num != self.agent_player_num: | |
self.continue_game() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SelfPlayEnv(env): | |
# ... | |
def continue_game(self): | |
while self.current_player_num != self.agent_player_num: | |
self.render() | |
action = self.current_agent.choose_action(self, choose_best_action = False, mask_invalid_actions = False) | |
observation, reward, done, _ = super(SelfPlayEnv, self).step(action) | |
logger.debug(f'Rewards: {reward}') | |
logger.debug(f'Done: {done}') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SelfPlayEnv(env): | |
# ... | |
def step(self, action): | |
self.render() | |
observation, reward, done, _ = super(SelfPlayEnv, self).step(action) | |
logger.debug(f'Action played by agent: {action}') | |
logger.debug(f'Rewards: {reward}') | |
logger.debug(f'Done: {done}') |
OlderNewer