-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposition_factory.py
73 lines (60 loc) · 1.96 KB
/
position_factory.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
import getting_a_position
def get_n_positions(n):
file_number =1
positions=[]
position_solutions=[]
i=0
while (file_number<=19):
file_name= f"{file_number}.pgn"
f = open(file_name, encoding="utf-8")
pgn=""
line=f.readline()
moves_played = []
while line:
pgn=pgn +line
if "result" in line.lower():
pgn=pgn + f.readline()
pgn=pgn + f.readline()
pgn=pgn + f.readline()
print('loading factory')
# if(i%10000==0): print(len(positions))
i+=1
if(n<=len(positions)):
yield (positions,position_solutions)
# f = open(file_name, encoding="utf-8")
positions=[]
position_solutions=[]
try:
new_positions,new_moves=getting_a_position.get_positions_and_moves_from_pgn(pgn)
positions.extend(new_positions)
position_solutions.extend(new_moves)
except Exception as e:
print(e)
pgn=""
line=f.readline()
f.close()
file_number+=1
if file_number >19: file_number = 1
return (positions,position_solutions)
# generator_obj=get_n_positions(1000)
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))
# print(len(generator_obj.__next__()[0]))