In [85]:
from chess import pgn
from chesslytics import chesslytics as cl
import numpy as np
from collections import Counter
import seaborn as sns
import matplotlib.pyplot as plt
In [89]:
%matplotlib inline
In [ ]:
In [126]:
pgn_file = open('../data/ficsgamesdb_201501_standard2000_nomovetimes_1276309.pgn')
In [148]:
num_games = 2000
In [149]:
game_list = []
curr_game = pgn.read_game(pgn_file)
while curr_game and len(game_list) < num_games:
data = cl.data_from_Game(curr_game)
if len(data[1]) > 10:
game_list.append(cl.Gamestats(*data))
curr_game = pgn.read_game(pgn_file)
In [150]:
len(game_list)
Out[150]:
In [151]:
game_lengths = [len(game.moves) for game in game_list]
In [152]:
min_length = min(game_lengths)
In [153]:
max_length = max(game_lengths)
In [ ]:
In [154]:
move_diversity = [len(set([game.moves[i] for game in game_list if len(game.moves) > i])) for i in xrange(max_length)]
In [155]:
normalized_move_diversity = [len(set([game.moves[i] for game in game_list if len(game.moves) > i]))/float(len([1 for game in game_list if len(game.moves) > i])) for i in xrange(max_length)]
In [156]:
plt.plot(move_diversity)
plt.ylabel('# distinct moves')
plt.xlabel('Turn')
plt.title('# distinct moves vs turn over {} games'.format(num_games))
plt.savefig('distinct_moves{}.png'.format(num_games), dpi=300)
In [157]:
plt.plot(normalized_move_diversity)
plt.ylabel('# distinct moves / # games')
plt.xlabel('Turn')
plt.title('# distinct moves by # games vs turn over {} games'.format(num_games))
plt.savefig('normalized_distinct_moves{}.png'.format(num_games), dpi=300)
In [74]:
first_moves = [game.moves[1] for game in game_list]
black_player = [game.headers['Black'] for game in game_list]
In [75]:
Counter(first_moves)
Out[75]:
In [40]:
g = game_list[0]
In [41]:
g
Out[41]:
In [42]:
g.headers['Black']
Out[42]:
In [62]:
g = [game for game in game_list if game.moves == []][0]
In [63]:
g.headers
Out[63]:
In [90]:
plt.plot(game_lengths)
Out[90]:
In [ ]:
In [ ]: