-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.py
More file actions
87 lines (70 loc) · 2.46 KB
/
core.py
File metadata and controls
87 lines (70 loc) · 2.46 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
86
87
import random
from datetime import datetime
from utils.config import Config
from utils.models import Attempt, AllAttempts, AllExpResults
class Core:
def start(self):
self.__start_game()
def __start_game(self):
self.__prepare_variables()
self.date_start = datetime.now().strftime("%d.%m.%Y %H:%M")
for game in range(1, self.config.attempts+1):
self.attempt = game
self.__prepare_doors()
self.__make_first_choice()
if self.config.change == 0:
self.switch = random.randint(0, 1)
elif self.config.change == 1:
self.switch = 1
elif self.config.change == 2:
self.switch = 0
else:
self.switch = 1
self.__open_doors()
if self.switch == 1:
self.choice = self.second_door
else:
pass
if self.choice == self.win_door:
self.win = 1
else:
self.win = 0
self.__move_attempt_to_db()
AllAttempts().move_conclusion_to_db(self.date_start)
print(AllExpResults().make_conclusion())
def __prepare_doors(self):
self.doors: list = []
self.win_door = random.randint(0, self.config.doors - 1)
for door in range(self.config.doors):
if door == self.win_door:
self.doors.append(1)
else:
self.doors.append(0)
def __make_first_choice(self):
self.choice = random.randint(0, self.config.doors - 1)
def __open_doors(self):
if self.choice == self.win_door:
self.second_door = random.choice(
[i for i in range(self.config.doors) if i not in [self.win_door, self.choice]]
)
else:
self.second_door = self.win_door
def __prepare_variables(self):
start = input(
"Please, enter 'Y' to start with default config,"
"or enter 'N' to setup yours"
)
if start.lower() == 'y':
self.__setup_config()
def __setup_config(self):
self.config = Config().default
def __move_attempt_to_db(self):
attempt = Attempt.init_from_dict(
{
'attempt': self.attempt,
'changed': self.switch,
'win': self.win,
'number_of_doors': self.config.doors
}
)
attempt.move_to_db()