-
Notifications
You must be signed in to change notification settings - Fork 14
/
team10.py
131 lines (109 loc) · 4.26 KB
/
team10.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
####
# 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'
####
def enum(**named_values):
return type('Enum', (), named_values)
team_name = 'HYPEBEASTS' # Only 10 chars displayed.
strategy_name = '[retacted]\'s Algorithm'
strategy_description = 'AI guided algrorithm that uses hyperthreaded databuffers to energize character generating flux capacieors. Uses quantum coupled machine learning to do error correction.'
Style = enum(STINGY=1, FAIR=2, GULLIBLE=3, PATTERNED=4, RANDOM=0)
style = Style.RANDOM
class style():
STINGY = 1 #always aggressive
FAIR = 2 #copies you
GULLIBLE = 3 #tends to pick collude more
PATTERNED = 4 #pattern
RANDOM = 5 #unknown/random
#test sequence
testSequence = 'cccbbbcbcb'
def move(my_history, their_history, my_score, their_score):
global style
''' Arguments accepted: my_history, their_history are strings.
my_score, their_score are ints.
Make my move.
Returns 'c' or 'b'.
'''
# my_history: a string with one letter (c or b) per round that has been played with this opponent.
# their_history: a string of the same length as history, possibly empty.
# The first round between these two players is my_history[0] and their_history[0].
# The most recent round is my_history[-1] and their_history[-1].
#Collude by default so there won't be an invalid move
returnValue = 'c'
prevMatches = len(their_history)
matchNum = prevMatches + 1
#Mimic by default normally
if prevMatches > 0:
returnValue = their_history[-1]
#Send test sequence
if prevMatches < len(testSequence):
returnValue = testSequence[prevMatches]
#Detect playstyle
if prevMatches == len(testSequence):
#Detect
#stingy
if(their_history[4:].upper()=='B'*(len(testSequence)-4)):
style = Style.STINGY
#fair
if(their_history[1:].upper()==testSequence.upper()):
style = Style.FAIR
#gullible
if(their_history[4:].upper()=='C'*(len(testSequence)-4)):
style = Style.GULLIBLE
#patterned
if('BCBCBCBC' in their_history.upper()):
style = Style.PATTERNED
if prevMatches >= len(testSequence):
if style == 1:
returnValue = 'c'
elif style == 2:
returnValue = 'c'
elif style == 3:
returnValue = 'b'
elif style == 4:
None
else:
#Just mimic
None
# #Ending move
# if len(my_history) == 99:
# returnValue = 'b'
return returnValue
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')