-
Notifications
You must be signed in to change notification settings - Fork 0
/
day2.py
71 lines (66 loc) · 2.28 KB
/
day2.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
class Move:
def __init__(self, symbol):
if (symbol == 'X'):
self.symbol = 'A'
elif (symbol == 'Y'):
self.symbol = 'B'
elif (symbol == 'Z'):
self.symbol = 'C'
else:
self.symbol = symbol
if (self.symbol == 'A'): # Rock
self.points = 1
elif (self.symbol == 'B'): # Paper
self.points = 2
elif (self.symbol == 'C'): # Scissors
self.points = 3
def compare(self, other):
if (self.symbol == other.symbol):
return 3 + self.points
elif (self.symbol == 'A' and other.symbol == 'B'):
return 0 + self.points
elif (self.symbol == 'A' and other.symbol == 'C'):
return 6 + self.points
elif (self.symbol == 'B' and other.symbol == 'A'):
return 6 + self.points
elif (self.symbol == 'B' and other.symbol == 'C'):
return 0 + self.points
elif (self.symbol == 'C' and other.symbol == 'A'):
return 0 + self.points
elif (self.symbol == 'C' and other.symbol == 'B'):
return 6 + self.points
def calculateSymbol(self, tactic):
mA = Move('A')
mB = Move('B')
mC = Move('C')
if (tactic == 'X'): # loose
if (self.symbol == 'A'):
return mC.compare(self)
if (self.symbol == 'B'):
return mA.compare(self)
if (self.symbol == 'C'):
return mB.compare(self)
elif (tactic == 'Y'): # draw
if (self.symbol == 'A'):
return 3 + 1
if (self.symbol == 'B'):
return 3 + 2
if (self.symbol == 'C'):
return 3 + 3
elif (tactic == 'Z'): # win
if (self.symbol == 'A'):
return mB.compare(self)
if (self.symbol == 'B'):
return mC.compare(self)
if (self.symbol == 'C'):
return mA.compare(self)
points = 0
points2 = 0
with open('day2_input.txt') as f:
for line in f:
enemyMove = Move(line[0])
myMove = Move(line[2])
points += myMove.compare(enemyMove)
points2 += enemyMove.calculateSymbol(line[2])
print(points)
print(points2)