-
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
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
-
185
-
186
-
187
-
188
-
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
207
-
208
-
209
#!/usr/bin/python
# Bet Starter File
# NOTE: You can run this file locally to test if your program is working.
#=============================================================================
# INPUT FORMAT: hand, others, card, scores
# hand: Your current hand (a list of integers 2 to 14)
# others: All other players' hands, in a fixed order
# card: The card currently being bet on (an integer 2 to 14)
# scores: All current scores of players (from this game only) in a
# fixed order. Your score is displayed as the first value.
# Example Input:
# hand: [2, 4, 14]
# others: [[6, 8, 9], [5, 11, 13]]
# card: 9
# scores: [34, 21, 18]
#=============================================================================
# OUTPUT FORMAT: A single integer between 2 and 14, inclusive, that is
# currently in your hand.
# Invalid outputs will result in your lowest card being played by default.
### WARNING: COMMENT OUT YOUR DEBUG/PRINT STATEMENTS BEFORE SUBMITTING !!!
### (this file uses standard IO to communicate with the grader!)
#=============================================================================
# Write your bot in the bet_bot class. Helper functions and standard library
# modules are allowed, and can be written before/inside these classes.
# You can define as many different strategies as you like, but only the class
# currently named "bet_bot" will be run officially.
# Example bot that plays a random card every round:
import random
class bet_bot:
def __init__(self):
# You can define global states (that last between moves) here
pass
def move(self, hand, others, card, scores):
# You should write your code that moves every turn here
return random.choice(hand)
#=============================================================================
# Local testing parameters
# If you would like to view a turn by turn game display while testing locally,
# set this parameter to True
LOCAL_VIEW = False
# Set a list of 3 strategies you would like to test locally
LOCAL_STRATS = [bet_bot(), bet_bot(), bet_bot()]
#=============================================================================
# You don't need to change any code below this point
import json
import sys
def WAIT():
return json.loads(input())
def SEND(data):
print(json.dumps(data), flush=True)
MASK = lambda a,i: a[:i] + a[i+1:]
def PLAY(players):
total = [0] * 3
for ROUND in range(1, 6):
scores = [0] * 3
hands = [[*range(2, 15)] for i in range(3)]
deck = [*range(2, 15)]
if LOCAL_VIEW:
print("ROUND",ROUND)
for _ in range(13):
card = random.choice(deck)
deck.remove(card)
if LOCAL_VIEW:
for i in range(3):
print(f"Player {i+1}'s hand:", ' '.join(map(str, hands[i])))
print("Card being bet on:", card)
values = []
for i in range(3):
try:
val=players[i].move(hands[i],MASK(hands,i),card,[scores[i]]+MASK(scores,i))
if not (val==int(val) and val in hands[i]):
raise Exception('invalid move')
except Exception as e:
print(f"Player {i+1} has an error: {e}! Playing the lowest card instead.")
val = min(hands[i])
values.append(val)
if LOCAL_VIEW:
print(f"Player {i+1}'s bet:", val)
for i in range(3):
hands[i].remove(values[i])
big = max(values)
if values.count(big) == 1:
if LOCAL_VIEW:
print(f"Player {values.index(big)+1} has won the card!")
scores[values.index(big)] += card
else:
if LOCAL_VIEW:
print("There was a tie! Nobody won the card.")
if LOCAL_VIEW:
print("Current totals:", ' '.join(map(str, scores)))
print()
input("Enter to continue (change LOCAL_VIEW to toggle this)")
for i in range(3):
scores[i] /= 100
big = max(scores)
tie = scores.count(big)
if tie == 3:
for i in range(3):
scores[i] += 1
elif tie == 2:
for i in range(3):
if scores[i] == big:
scores[i] += 2
else:
scores[i] += 1
else:
index = scores.index(big)
scores[index] += 5
small = min(scores)
for i in range(3):
if scores[i] == small:
scores[i] += 1
elif i != index:
scores[i] += 2
for i in range(3):
total[i] += scores[i]
print()
print("Round",ROUND,"scores:",' '.join(map(str, scores)))
print()
print("Game finished!")
print("Final scores:",' '.join(map(str, total)))
if not LOCAL_VIEW:
print("Change LOCAL_VIEW to True to see a turn by turn replay")
if len(sys.argv) < 2 or sys.argv[1] != 'REAL':
PLAY(LOCAL_STRATS)
input()
else:
player = bet_bot()
while True:
data = WAIT()
play = player.move(data["hand"],data["others"],data["card"],data["scores"])
SEND(play)