How to use the axelrod.random_.random_choice function in Axelrod

To help you get started, we’ve selected a few Axelrod examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Axelrod-Python / Axelrod / axelrod / strategies / axelrod_first.py View on Github external
def strategy(opponent: Player) -> Action:
        r = random.uniform(3, 7) / 10
        return random_choice(r)
github Axelrod-Python / Axelrod / axelrod / strategies / averagecopier.py View on Github external
def strategy(self, opponent: Player) -> Action:
        if len(opponent.history) == 0:
            return C
        p = opponent.cooperations / len(opponent.history)
        return random_choice(p)
github Axelrod-Python / Axelrod / axelrod / strategies / axelrod_first.py View on Github external
def strategy(opponent: Player) -> Action:
        r = random.uniform(3, 7) / 10
        return random_choice(r)
github Axelrod-Python / Axelrod / axelrod / strategies / rand.py View on Github external
def strategy(self, opponent: Player) -> Action:
        return random_choice(self.p)
github Axelrod-Python / Axelrod / axelrod / strategies / axelrod_first.py View on Github external
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)
github Axelrod-Python / Axelrod / axelrod / strategies / worse_and_worse.py View on Github external
def strategy(self, opponent: Player) -> Action:
        current_round = len(self.history) + 1
        probability = 1 - current_round / 1000
        return random_choice(probability)
github Axelrod-Python / Axelrod / axelrod / strategies / prober.py View on Github external
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
github Axelrod-Python / Axelrod / axelrod / strategies / titfortat.py View on Github external
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]
github Axelrod-Python / Axelrod / axelrod / strategies / geller.py View on Github external
def foil_strategy_inspection() -> Action:
        """Foils _strategy_utils.inspect_strategy and _strategy_utils.look_ahead"""
        return random_choice(0.5)
github Axelrod-Python / Axelrod / axelrod / strategies / hmm.py View on Github external
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