Skip to content

Commit

Permalink
random agent runs
Browse files Browse the repository at this point in the history
  • Loading branch information
tsor13 committed Feb 15, 2024
1 parent b518aa2 commit 0a4b3d2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions machiavelli/agent/random_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from machiavelli.agent.base_agent import BaseAgent
import numpy as np


class RandomAgent(BaseAgent):
def __init__(self):
super().__init__()

def get_action(self, obs, rew, done, info):
if done:
return None
return np.random.choice(info['game_state']['num_choices'])

def get_action_probabilities(self, obs, rew, done, info):
num_actions = info['game_state']['num_choices']
return [1 / num_actions for _ in range(num_actions)]

def train(self):
pass

def test(self):
pass
2 changes: 1 addition & 1 deletion machiavelli/game/machiavelli_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def _get_info(self):
@property
def action_space(self):
# We have N choices at each state, but N changes depending on the state
action_space = gym.spaces.Discrete(self.player.get_action_space())
action_space = gym.spaces.Discrete(max(self.player.get_action_space(), 1))
return action_space

@property
Expand Down

0 comments on commit 0a4b3d2

Please sign in to comment.