Skip to content

Commit d5fbd47

Browse files
adds test to increase coverage, in particular coverage of ShouldDemote mecanism
1 parent 1bc6a34 commit d5fbd47

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

axelrod/strategies/dbs.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,16 @@ def minimax_tree_search(begin_node, policy, max_depth):
346346
# depth is < max_depth
347347
siblings = begin_node.get_siblings()
348348
# The stochastic node value is the expected values of siblings
349-
node_value = (begin_node.pC * minimax_tree_search(siblings[0], policy, max_depth)
350-
+ (1 - begin_node.pC) * minimax_tree_search(siblings[1], policy, max_depth))
349+
node_value = (
350+
begin_node.pC * minimax_tree_search(
351+
siblings[0],
352+
policy,
353+
max_depth)
354+
+ (1 - begin_node.pC) * minimax_tree_search(
355+
siblings[1],
356+
policy,
357+
max_depth)
358+
)
351359
return node_value
352360
else: # determinist node
353361
if begin_node.depth == max_depth:
@@ -358,8 +366,10 @@ def minimax_tree_search(begin_node, policy, max_depth):
358366
# this returns the two max expected values, for choice C or D,
359367
# as a tuple
360368
return (
361-
minimax_tree_search(siblings[0], policy, max_depth) + begin_node.get_value(),
362-
minimax_tree_search(siblings[1], policy, max_depth) + begin_node.get_value()
369+
minimax_tree_search(siblings[0], policy, max_depth)
370+
+ begin_node.get_value(),
371+
minimax_tree_search(siblings[1], policy, max_depth)
372+
+ begin_node.get_value()
363373
)
364374
elif begin_node.depth < max_depth:
365375
siblings = begin_node.get_siblings(policy)
-12 KB
Binary file not shown.

axelrod/tests/strategies/test_dbs.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,24 @@ def test_strategy(self):
6969
expected_actions=exp_actions,
7070
init_kwargs = init_kwargs_2
7171
)
72+
73+
# check that ShouldDemote mecanism works.
74+
# We play against Alternator during 12 turns to make the
75+
# algorithm learn Alternator's strategy, then at turn 13 we
76+
# change opponent to Defector, hence trigging ShouldDemote
77+
# mecanism
78+
# For this test we use violation_threshold=3
79+
init_kwargs_3 = {
80+
'discount_factor':.75, 'promotion_threshold':3,
81+
'violation_threshold':3, 'reject_threshold':3,
82+
'tree_depth':5
83+
}
84+
exp_actions = [(C, C), (C, D)] * 3 + [(D, C), (C, D)] * 3
85+
exp_actions += [(D, D), (C, D)] * 3 + [(D, D)]
86+
mock_actions = [C, D, C, D, C, D, C, D, C, D, C, D, D, D, D, D, D, D, D]
87+
self.versus_test(
88+
opponent=axelrod.MockPlayer(actions=mock_actions),
89+
expected_actions=exp_actions,
90+
init_kwargs = init_kwargs_3
91+
)
7292

0 commit comments

Comments
 (0)