-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaster_class.py
49 lines (43 loc) · 1.48 KB
/
master_class.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
import random
class Mastermind:
def __init__(self, rows, rn, dup=False):
self.rows = rows
self.rn = rn
self.dup = dup
self.temp_ans = ""
self.game_history = []
def menu(self):
temp_ans = ""
while len(temp_ans) < self.rows:
answer = random.randint(1, self.rn)
if self.dup:
temp_ans += str(answer)
else:
if str(answer) not in temp_ans:
temp_ans += str(answer)
self.temp_ans = temp_ans
print(f"Playing Mastermind with {self.rn} positions and {self.rows} positions")
print(f"duplicates set as {self.dup}")
def playing(self):
guess = input(f"input {self.rows} numbers: ")
if guess == "hint":
print("Hint:")
print(f"one of the answers is {self.temp_ans[random.randint(1, (self.rows - 1))]}")
output = ""
for i in range(self.rows):
if guess[i] == self.temp_ans[i]:
output += "0"
elif guess[i] in self.temp_ans:
output += "X"
else:
output += "_"
for i in range(len(output)):
print(f"[{output[i]}]", end=" ")
self.game_history.append([guess, output])
print()
if guess == self.temp_ans:
print("you win good job")
print()
return False
else:
return True