Skip to content

Commit

Permalink
Enable getting policy when no legal actions
Browse files Browse the repository at this point in the history
This is linked to google-deepmind#588
  • Loading branch information
TheoCabannes committed Jun 8, 2021
1 parent cfe17d1 commit b303e31
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions open_spiel/python/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ def action_probabilities(self, state, player_id=None):
probability = self.policy_for_key(self._state_key(state, player_id))
legal_actions = (state.legal_actions() if player_id is None
else state.legal_actions(player_id))
if not legal_actions:
return {0: 1.0}
return {action: probability[action] for action in legal_actions}

def state_index(self, state):
Expand Down Expand Up @@ -356,6 +358,8 @@ def action_probabilities(self, state, player_id=None):
"""
legal_actions = (state.legal_actions() if player_id is None
else state.legal_actions(player_id))
if not legal_actions:
return {0: 1.0}
probability = 1 / len(legal_actions)
return {action: probability for action in legal_actions}

Expand All @@ -370,6 +374,8 @@ def __init__(self, game):
def action_probabilities(self, state, player_id=None):
legal_actions = (state.legal_actions() if player_id is None
else state.legal_actions(player_id))
if not legal_actions:
return {0: 1.0}
min_action = min(legal_actions)
return {action: 1.0 if action == min_action else 0.0
for action in legal_actions}
Expand Down

0 comments on commit b303e31

Please sign in to comment.