Skip to content

Commit

Permalink
Update variable names for Adaptor and update docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
marcharper committed Oct 30, 2018
1 parent 54da931 commit aa9a114
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions axelrod/strategies/adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ class AbstractAdaptor(Player):
round of play. Using this state the player Cooperates with a probability
derived from the state.
Parameters
----------
s, float:
the internal state, initially 0
perr, float:
an error threshold for misinterpreted moves
delta, a dictionary of floats:
additive update values for s depending on the last round's outcome
Names:
- Adaptor: [Hauert2002]_
Expand All @@ -32,18 +41,18 @@ class AbstractAdaptor(Player):
"manipulates_state": False,
}

def __init__(self, d: Dict[Tuple[Action, Action], float],
def __init__(self, delta: Dict[Tuple[Action, Action], float],
perr: float = 0.01) -> None:
super().__init__()
self.perr = perr
self.d = d
self.delta = delta
self.s = 0.

def strategy(self, opponent: Player) -> Action:
if self.history:
# Update internal state from the last play
last_round = (self.history[-1], opponent.history[-1])
self.s += self.d[last_round]
self.s += self.delta[last_round]

# Compute probability of Cooperation
p = self.perr + (1.0 - 2 * self.perr) * (
Expand All @@ -66,12 +75,13 @@ class AdaptorBrief(AbstractAdaptor):
name = "AdaptorBrief"

def __init__(self) -> None:
d = {(C, C): 0., # R
(C, D): -1.001505, # S
(D, C): 0.992107, # T
(D, D): -0.638734 # P
}
super().__init__(d=d)
delta = {
(C, C): 0., # R
(C, D): -1.001505, # S
(D, C): 0.992107, # T
(D, D): -0.638734 # P
}
super().__init__(delta=delta)


class AdaptorLong(AbstractAdaptor):
Expand All @@ -87,9 +97,10 @@ class AdaptorLong(AbstractAdaptor):
name = "AdaptorLong"

def __init__(self) -> None:
d = {(C, C): 0., # R
(C, D): 1.888159, # S
(D, C): 1.858883, # T
(D, D): -0.995703 # P
}
super().__init__(d=d)
delta = {
(C, C): 0., # R
(C, D): 1.888159, # S
(D, C): 1.858883, # T
(D, D): -0.995703 # P
}
super().__init__(delta=delta)

0 comments on commit aa9a114

Please sign in to comment.