-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
97 lines (73 loc) · 2.69 KB
/
main.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
from constant import RULES, CHOICE_ELEMENT, scoreset
from random import choice
from decorators import log_time
number_of_set = int(input('please insert number of total set? : '))
# Number of matches per set
number_of_match = int(input('please insert number of total match in per set? : '))
def system_choice():
return choice(RULES)
def user_choice():
user = input("please insert your choice(r,p,s)?: ")
if user not in RULES:
print("OOOps!!!! your choice is incorect , please insert again?")
return user_choice()
return user
def find_winner(user_choice1, system_choice1):
choices_system_user = {user_choice1, system_choice1}
if len(choices_system_user) == 1:
return None
result = tuple(sorted(choices_system_user))
return CHOICE_ELEMENT[result]
counter_of_set = 0
def calculate_set(scoreboard):
global counter_of_set
counter_of_set += 1
if scoreboard['system'] == number_of_match:
msg_set = f'You lose set {counter_of_set}'
scoreset['system_set'] += 1
else:
msg_set = f'You win set {counter_of_set}'
scoreset['user_set'] += 1
print('#' * 50)
print(msg_set)
print(f'scoreset in match : system - user : {scoreset["system_set"]} - {scoreset["user_set"]}')
print('#' * 50)
if counter_of_set < number_of_set:
play_one_hand()
elif scoreset['system_set'] == number_of_set:
print('/' * 30)
msg_end = f" end of finell " \
f"winner is system "
print(msg_end)
print('/' * 30)
else:
print('/' * 30)
msg_end = f" end of finell " \
f"winner is user "
print(msg_end)
print('/' * 30)
def play_one_hand():
scoreboard = {'user': 0, 'system': 0}
while (scoreboard['user'] < number_of_match) and (scoreboard['system'] < number_of_match):
user = user_choice()
system = system_choice()
winner = find_winner(user, system)
if winner == user:
scoreboard['user'] += 1
msg = " You win"
elif winner == system:
scoreboard['system'] += 1
msg = "You lose"
else:
msg = 'Draw'
print('*' * 50)
print(f'system choice: {system} user choice : {user} result : {msg}')
print(f'scoreboard in match : system - user : {scoreboard["system"]} - {scoreboard["user"]}')
print('*' * 50)
if scoreset['system_set'] < number_of_set and scoreset["user_set"] < number_of_set:
calculate_set(scoreboard)
@log_time
def play():
play_one_hand()
if __name__ == '__main__':
play()