-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRockPaperScissor.py
More file actions
29 lines (26 loc) · 1.04 KB
/
Copy pathRockPaperScissor.py
File metadata and controls
29 lines (26 loc) · 1.04 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
def winner(t_elf, t_me):
win = 0 if t_elf > t_me else 6 if t_me > t_elf else 3
point = 6 if t_me + t_elf == 4 and win == 0 else 0 if t_me + t_elf == 4 and win == 6 else win
point += t_me
return point
def calcStrategy(t_elf,outcome):
elf = t_elf-1
strat = (elf + 1) % 3 if outcome == 'Z' else (elf - 1) % 3 if outcome == 'X' else elf
return strat + 1
def tournament(file):
print("****** Tournament ******")
score = 0
for line in file.splitlines():
elf, me = str(line).split(" ")
t_elf = 1 if elf == 'A' else 2 if elf == 'B' else 3 if elf == 'C' else 0
t_me = 1 if me == 'X' else 2 if me == 'Y' else 3 if me == 'Z' else 0
score += winner(t_elf, t_me)
return score
def tournament_cheat(file):
score = 0
for line in file.splitlines():
elf, outcome = str(line).split(" ")
t_elf = 1 if elf == 'A' else 2 if elf == 'B' else 3 if elf == 'C' else 0
t_me = calcStrategy(t_elf, outcome)
score += winner(t_elf, t_me)
return score