-
Notifications
You must be signed in to change notification settings - Fork 0
/
basics.py
109 lines (91 loc) · 3.06 KB
/
basics.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
import chess.pgn
import matplotlib
from matplotlib import pyplot as plt
data = open('Data/lichess_db_standard_rated_2014-03.pgn', encoding="utf-8")
# the number of games
N = 795173
# First, count for each Event type.
List = []
N_Classic =0
N_Blitz =0
N_Bullet = 0
N_Other =0
for i in range(N):
game = chess.pgn.read_game(data)
if game.headers["Event"] == 'Rated Classical game':
N_Classic = N_Classic + 1
else:
if game.headers["Event"] == 'Rated Blitz game':
N_Blitz = N_Blitz + 1
else:
if game.headers["Event"] == 'Rated Bullet game':
N_Bullet = N_Bullet + 1
else:
N_Other = N_Other + 1
print(N_Classic, N_Blitz, N_Bullet, N_Other)
'''
# N_Classic = 269294
# N_Blitz = 285058
# N_Bullet = 220030
# N_Other = 20791
Classic_Per = N_Classic/float(N)
Blitz_Per = N_Blitz/float(N)
Bullet_Per = N_Bullet/float(N)
print(Classic_Per, Blitz_Per, Bullet_Per)
'''
'''
# Second, see all openings played:
Openings = []
game = chess.pgn.read_game(data)
previous = game.headers["Opening"]
Openings.append(previous)
for i in range(N):
game = chess.pgn.read_game(data)
if game.headers["Opening"] not in Openings:
Openings.append(game.headers["Opening"])
M = len(Openings)
print(Openings)
Classical = [0] * M
Blitz = [0] * M
Bullet = [0] * M
# Third, for each opening, I compute how many classic, blitz, or bullet were played
# Group by opening and then by event type
for i in range(N):
game = chess.pgn.read_game(data)
for j in range(M):
if Openings[j] == game.headers["Opening"]:
if game.headers["Event"] == 'Rated Classical game':
Classical[j] = Classical[j] + 1
else:
if game.headers["Event"] == 'Rated Blitz game':
Blitz[j] = Blitz[j] + 1
else:
if game.headers["Event"] == 'Rated Bullet game':
Bullet[j] = Bullet[j] + 1
# Fourth, I calculate the percentages
occ = [0] * M
for i in range(M):
occ[i] = Classical[i] + Bullet[i] + Blitz[i]
Classical_Per = [0] * M
for i in range(M):
Classical_Per[i] = Classical[i] * 100/float(occ[i])
# Fifth, check if there are other reasons to finish a game other than normal of time forfeit.
Terminations = ['Normal','Time forfeit']
for i in range(N):
game = chess.pgn.read_game(data)
if (game.headers["Termination"] != 'Normal') and (game.headers["Termination"] != 'Time forfeit'):
Terminations.append(game.headers["Termination"])
# Sixth, I was trying to find out the ratios of games with increment
Classic_With_Increment = ['600+10']
N_With = 0
Classic_With_Out_Increment = ['900+0']
N_WithOut = 0
Blitz_Time_Control = ['240+0']
for i in range(N):
game = chess.pgn.read_game(data)
if game.headers["Event"] == 'Rated Classical game':
if game.headers["TimeControl"][4] != 0:
N_With = N_With + 1
else:
N_WithOut = N_WithOut + 1
'''