def string_to_interactions(string): """ Converts a compact string representation of an interaction to an interaction: 'CDCDDD' -> [(C, D), (C, D), (D, D)] """ interactions = [] interactions_list = list(string) while interactions_list: p1action = Action.from_char(interactions_list.pop(0)) p2action = Action.from_char(interactions_list.pop(0)) interactions.append((p1action, p2action)) return interactions
def _get_human_input(self) -> Action: # pragma: no cover """ A method to prompt the user for input, validate it and display the bottom toolbar. Returns ------- string Uppercase C or D indicating the action to play """ action = prompt( 'Turn {} action [C or D] for {}: '.format( len(self.history) + 1, self.human_name), validator=ActionValidator(), get_bottom_toolbar_tokens=self.status_messages['toolbar'], style=toolbar_style) return Action.from_char(action.upper())
def random_flip(action: Action, threshold: float) -> Action: """ Return flipped action with probability `threshold` No random sample is carried out if threshold is 0 or 1. Parameters ---------- action: The action to flip or not threshold : float The probability of flipping action Returns ------- axelrod.Action """ if random_choice(threshold) == C: return action.flip() return action
def _get_human_input(self) -> Action: # pragma: no cover """ A method to prompt the user for input, validate it and display the bottom toolbar. Returns ------- string Uppercase C or D indicating the action to play """ action = prompt( "Turn {} action [C or D] for {}: ".format( len(self.history) + 1, self.human_name ), validator=ActionValidator(), style=toolbar_style, **{bottom_toolbar_name: self.status_messages["toolbar"]}, ) return Action.from_char(action.upper())