-
Notifications
You must be signed in to change notification settings - Fork 14
/
team14.py
80 lines (74 loc) · 2.8 KB
/
team14.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
####
# Each team's file must define four tokens:
# team_name: a string
# strategy_name: a string
# strategy_description: a string
# move: A function that returns 'c' or 'b'
####
team_name = 'QueenBee' # Only 10 chars displayed.
strategy_name = 'DanceTheDance'
strategy_description = 'fingerprint to workerbees'
def move(my_history, their_history, my_score, their_score):
''' Arguments accepted: my_history, their_history are strings.
my_score, their_score are ints.
Make my move.
Returns 'c' or 'b'.
'''
# Analyze my_history and their_history and/or my_score and their_score.
# Decide whether to return 'c' or 'b'.
if len(their_history)==0:
return 'c' # FingerPrint
elif len(their_history)==1:
return 'c'
elif len(their_history)==2:
return 'c'
elif len(their_history)==3:
return 'b'
elif len(their_history)==4:
return 'c'
elif len(their_history)==5:
return 'c'
elif len(their_history)==6:
return 'b'
elif len(their_history)==7:
return 'b'
elif len(their_history)==8:
return 'c'
else: #### After Fingerprint has been sent always betray
return 'b'
# return 'c'
def test_move(my_history, their_history, my_score, their_score, result):
'''calls move(my_history, their_history, my_score, their_score)
from this module. Prints error if return value != result.
Returns True or False, dpending on whether result was as expected.
'''
real_result = move(my_history, their_history, my_score, their_score)
if real_result == result:
return True
else:
print("move(" +
", ".join(["'"+my_history+"'", "'"+their_history+"'",
str(my_score), str(their_score)])+
") returned " + "'" + real_result + "'" +
" and should have returned '" + result + "'")
return False
#if __name__ == '__main__':
# # Test 1: Betray on first move.
# if test_move(my_history='',
# their_history='',
# my_score=0,
# their_score=0,
# result='b'):
# print 'Test passed'
# # Test 2: Continue betraying if they collude despite being betrayed.
# test_move(my_history='bbb',
# their_history='ccc',
# # Note the scores are for testing move().
# # The history and scores don't need to match unless
# # that is relevant to the test of move(). Here,
# # the simulation (if working correctly) would have awarded
# # 300 to me and -750 to them. This test will pass if and only if
# # move('bbb', 'ccc', 0, 0) returns 'b'.
# my_score=0,
# their_score=0,
## result='b')####