Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def strategy(opponent: Player) -> Action:
r = random.uniform(3, 7) / 10
return random_choice(r)
def strategy(self, opponent: Player) -> Action:
if len(opponent.history) == 0:
return C
p = opponent.cooperations / len(opponent.history)
return random_choice(p)
def strategy(opponent: Player) -> Action:
r = random.uniform(3, 7) / 10
return random_choice(r)
def strategy(self, opponent: Player) -> Action:
return random_choice(self.p)
def strategy(self, opponent: Player) -> Action:
round_number = len(self.history) + 1
if round_number < 3:
return C
if round_number < 8:
return opponent.history[-1]
if self.history[-1] == opponent.history[-1]:
return C
return random_choice(2 / 7)
def strategy(self, opponent: Player) -> Action:
current_round = len(self.history) + 1
probability = 1 - current_round / 1000
return random_choice(probability)
def strategy(self, opponent: Player) -> Action:
# First move
if len(self.history) == 0:
return C
# React to the opponent's last move
if opponent.history[-1] == D:
return D
# Otherwise cooperate, defect with probability 1 - self.p
choice = random_choice(1 - self.p)
return choice
def strategy(self, opponent: Player) -> Action:
if not self.history:
return C
if self.is_defector:
return D
if self.history[-1] == D and opponent.history[-1] == C:
decision = random_choice()
if decision == C:
return C
else:
self.is_defector = True
return D
return opponent.history[-1]
def foil_strategy_inspection() -> Action:
"""Foils _strategy_utils.inspect_strategy and _strategy_utils.look_ahead"""
return random_choice(0.5)
def move(self, opponent_action: Action) -> Action:
"""Changes state and computes the response action.
Parameters
opponent_action: Axelrod.Action
The opponent's last action.
"""
num_states = len(self.emission_probabilities)
if opponent_action == C:
next_state = choice(num_states, 1, p=self.transitions_C[self.state])
else:
next_state = choice(num_states, 1, p=self.transitions_D[self.state])
self.state = next_state[0]
p = self.emission_probabilities[self.state]
action = random_choice(p)
return action