-
Notifications
You must be signed in to change notification settings - Fork 1
/
quadra_baseball.py
72 lines (65 loc) · 1.65 KB
/
quadra_baseball.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
import os
import random
def enable(user_id):
profile_name = "baseball_telegram_database/"+str(user_id)+".txt"
if os.path.exists(profile_name):
return True
else:
return False
def start(user_id):
profile_name = "baseball_telegram_database/"+str(user_id)+".txt"
if enable(user_id):
return -1
else:
answer = [10,10,10]
for i in range(0,3,1):
swt = True
while(swt):
temp = random.randrange(0,10)
if temp in answer:
continue
else:
answer[i] = temp
swt = False
answer = answer[0]*100+answer[1]*10+answer[2]
fp = open(profile_name, 'a')
fp.write(str(answer))
fp.write("\n")
fp.write("0")
fp.close()
return answer
def gameManager(target,answer):
alpha = [target//100,(target%100)//10,target%10]
beta = [answer//100,(answer%100)//10,answer%10]
strike = 0
ball = 0
for i in range(0,3,1):
for j in range(0,3,1):
if alpha[i] == beta[j]:
if i == j: strike += 1
else: ball += 1
return [strike,ball]
def check(user_id):
profile_name = "baseball_telegram_database/"+str(user_id)+".txt"
if enable(user_id):
fp = open(profile_name,'r')
target = fp.readlines()
target[1] = int(target[1])
fp.close()
return target
def check_equal(target):
alpha = [target//100,(target%100)//10,target%10]
for i in range(0,2,1):
for j in range(i+1,3,1):
if alpha[i] == alpha[j] : return False
return True
def lose(user_id):
profile_name = "baseball_telegram_database/"+str(user_id)+".txt"
temp = check(user_id)
temp[1] += 1
fp = open(profile_name,'w')
fp.write(str(temp[0])+str(temp[1]))
fp.close()
def end(user_id):
profile_name = "baseball_telegram_database/"+str(user_id)+".txt"
os.remove(profile_name)