-
Notifications
You must be signed in to change notification settings - Fork 0
/
RPS.py
102 lines (86 loc) · 3.25 KB
/
RPS.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
# The example function below keeps track of the opponent's history and plays whatever the opponent played two plays ago. It is not a very good player so you will need to change the code to pass the challenge.
my_history = []
init_play = prev_play = 'S'
opponent_list = [False, False, False, False]
ideal_response = {'P' : 'R', 'R' : 'S', 'S' : 'P'}
opponent_quincy_counter = -1
play_order = [{
"RR" : 0,
"RP" : 0,
"RS" : 0,
"PR" : 0,
"PP" : 0,
"PS" : 0,
"SR" : 0,
"SP" : 0,
"SS" : 0,
}]
def player(prev_opponent_play, opponent_history = []):
global my_history, prev_play, opponent_list, ideal_response, opponent_quincy_counter, play_order
opponent_history.append(prev_opponent_play)
my_history.append(prev_play)
# quincy
if(len(set(opponent_list)) == 1 and opponent_history[-5:] == ['R', 'P', 'P', 'S', 'R']):
opponent_list[0] = True
if(opponent_list[0]):
if(len(opponent_history) % 1000 == 0):
opponent_list = [False, False, False, False]
opponent_history.clear()
opponent_quincy_list = ['P', 'S', 'S', 'R', 'P']
opponent_quincy_counter = (opponent_quincy_counter + 1) % 5
return opponent_quincy_list[opponent_quincy_counter]
# abbey
if(len(set(opponent_list)) == 1 and opponent_history[-5:] == ['P', 'P', 'R', 'R', 'R']):
opponent_list[1] = True
if(opponent_list[1]):
last_two = ''.join(my_history[-2:])
if(len(last_two) == 2):
play_order[0][last_two] += 1
potential_plays = [
prev_play + 'R',
prev_play + 'P',
prev_play + 'S',
]
sub_order = {
k : play_order[0][k]
for k in potential_plays if k in play_order[0]
}
prediction = max(sub_order, key = sub_order.get)[-1:]
if(len(opponent_history) % 1000 == 0):
opponent_list = [False, False, False, False]
opponent_history.clear()
play_order = [{
"RR" : 0,
"RP" : 0,
"RS" : 0,
"PR" : 0,
"PP" : 0,
"PS" : 0,
"SR" : 0,
"SP" : 0,
"SS" : 0,
}]
prev_play = ideal_response[prediction]
return prev_play
# kris
if(len(set(opponent_list)) == 1 and opponent_history[-5:] == ['P', 'R', 'R', 'R', 'R']):
opponent_list[2] = True
if(opponent_list[2]):
if(len(opponent_history) % 1000 == 0):
opponent_list = [False, False, False, False]
opponent_history.clear()
prev_play = ideal_response[prev_play]
return prev_play
# mrugesh
if(len(set(opponent_list)) == 1 and opponent_history[-5:] == ['R', 'R', 'R', 'R', 'R']):
opponent_list[3] = True
if(opponent_list[3]):
if(len(opponent_history) == 1000):
opponent_list = [False, False, False, False]
opponent_history.clear()
last_ten = my_history[-10:]
most_frequent = max(set(last_ten), key = last_ten.count)
prev_play = ideal_response[most_frequent]
return prev_play
prev_play = init_play
return prev_play