-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinvalidquit.py
More file actions
85 lines (46 loc) · 1.48 KB
/
Copy pathinvalidquit.py
File metadata and controls
85 lines (46 loc) · 1.48 KB
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
#!/usr/bin/python3
#This program is invalid, and is used only to test the supervisor.
import sys
def run():
numRounds=1 # number of rounds starts at 1 because yall don't know how to program
opponentMoves=[]
myMoves=[]
while True:
myMove = main(numRounds, opponentMoves, myMoves)
if myMove:
sys.stdout.buffer.write(b"\x01")
myMoves.append(True)
else:
sys.stdout.buffer.write(b"\x00")
myMoves.append(False)
# possible outputs are \x00 and \x01. anything else is invalid.
sys.stdout.flush()
theirMove = sys.stdin.buffer.read(1)
if theirMove==b"":
return # game is over
if theirMove==b"\x01":
opponentMoves.append(True)
else:
opponentMoves.append(False)
numRounds=numRounds+1
if numRounds > 20:
return # INVALID -- quits after 20 rounds
#your code below this line
def main(rounds, opMoves, myMoves): # example tit for tat
if rounds == 1:
return True
if opMoves[-1] == 1:
return True
if opMoves[-1] == 0:
return False
# a way to check if your code is working:
# printf "\x00\x00\x01\x01\x00" | python3 program.py | hexdump
# it will print out what it would move (in the same format of 00 = defect, 01 = coop) against defect defect coop coop defect
# if your program prints out anything but \x00 or \x01 it is invalid.
# example correct tit for tat output
# $ printf "\x00\x00\x01\x01" | python3 example.py | hexdump
# 0000000 01 00 00 01 01
# 0000005
# $
# put this at the end
run()