Skip to content

Instantly share code, notes, and snippets.

@alasdairham
Created July 21, 2017 05:04
Show Gist options
  • Select an option

  • Save alasdairham/81ceb2ae2deee18b6c948d6215a04690 to your computer and use it in GitHub Desktop.

Select an option

Save alasdairham/81ceb2ae2deee18b6c948d6215a04690 to your computer and use it in GitHub Desktop.
class Player:
# ....
def regret(self, my_action, opp_action):
"""
We here define the regret of not having chosen an action as the difference between the utility of that action and the utility of the action we actually chose, with respect to the fixed choices of the other player. Compute the regret and add it to regret sum.
"""
result = RPS.utilities.loc[my_action, opp_action]
facts = RPS.utilities.loc[:, opp_action].values
regret = facts - result
self.regret_sum += regret
def action(self, use_avg=False):
"""
select an action according to strategy probabilities
"""
strategy = self.avg_strategy if use_avg else self.strategy
return np.random.choice(RPS.actions, p=strategy) # p refers to 'probability'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment