forked from Jamee999/cricket
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustom.py
133 lines (110 loc) · 2.78 KB
/
custom.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import random, time, copy, os, shutil, datetime
from callcricketnew import test, innings, bowling, player, team, quickorder, listshow, playerwrite
from game import game, setup
from historical import series
def possible():
a, c = [], []
with open ('customteams.txt') as g:
for line in g: a.append(line[:-1])
n = 0
for i in a:
if i == '': c.append(a[n+1])
n +=1
return c, a
def find (t, a):
p = []
read = False
for i in a:
if read == True and i != '': p.append(i)
if i == t: read = True
if i == '': read = False
return p
def playermake (x, t):
p = player ()
x = x[2:-3].split(',')
p.name = x[0][:-1]
p.team = t.name
p.bat = float(x[1])
p.bowl = float(x[2])
p.tag = x[3][2:-1]
p.first = int(x[4])
p.last = int(x[5])
p.sr = float(x[6])
p.er = float(x[7])
p.capt = int(x[8])
#longdesc (p)
return p
def load (t, *q):
c, a = possible()
t.name = False
for i in q:
if i in c:
c.remove(q)
while t.name not in c:
t.name = input('Select a team from: {} -- '.format(listshow(c)))
p = find (t.name, a)
for i in p:
t.active.append(playermake(i,t))
return t
def getplayers():
import pickle
pickle_in = open("players","rb")
players = pickle.load(pickle_in)
return players
def make (x):
p = getplayers()
while len(x.active) < 11 or add == True:
print ()
n = input("Please enter a player's name. ")
e = [x for x in p if n == x.name]
f = [x.name for x in p if n in x.name]
if len(e) > 1:
j = 1
for i in e:
print (j, i.name, i.team, i.tag, 'First', i.first, 'Last', i.last)
j+=1
k = input('Enter the number of the player you wish to select. ')
try:
x.active.append(e[int(k)-1])
print ('Success - player in database added to team.')
except:
print ('Player not found, please try again.')
continue
elif len(e) == 1:
e[0].team = x.name
x.active.append(e[0])
print ('Success - player in database added to team.')
elif len(e) == 0 and len(f) > 0:
print ('Did you mean one of these players?', end= ' ')
print (listshow(f))
else: print ('Player not found, please try again.')
if len(x.active) >= 11:
add = input("Type 'y' to keep adding players, or any other button to end. ")
if add == 'y':
add = True
with open ('customteams.txt', 'a') as g:
g.write('\n')
g.write(str(x.name))
g.write('\n')
for i in x.active:
g.write(playerwrite(i))
g.write('\n')
return x
def getcustom (*q):
o = ''
while o not in ['l', 'n']: o = input("Type 'l' to load an existing custom team, or 'n' to create a new one. ")
if o == 'l':
x = team()
t = load (x, q)
if o == 'n':
x = input('Type name of team: ')
a = team()
a.name = x
t = make (a)
print ()
return t
if __name__ == "__main__":
q = []
for i in range(2):
q.append(getcustom())
series (q[0].name, q[1].name, q[0].active, q[1].active)