Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import chess.pgn
  2.  
  3. PGN_PATH = 'test.pgn'
  4.  
  5. def average_time_per_move(pgn_file):
  6. pgn = open(pgn_file, encoding="utf-8-sig")
  7. stats = {} #format {engine_name : [total_time, nr_of_samples]}
  8. while True:
  9. game = chess.pgn.read_game(pgn)
  10. if game is None:
  11. break
  12. white_engine = game.headers['White']
  13. black_engine = game.headers['Black']
  14. engines = [white_engine, black_engine]
  15.  
  16. for engine in engines:
  17. if engine not in stats.keys():
  18. stats[engine] = [0.0, 0]
  19. node = game
  20. ply_nr = 0
  21. while not node.is_end():
  22. next_node = node.variations[0]
  23. engine = engines[ply_nr % 2]
  24. comment = node.comment
  25. if comment != 'book' and comment != '':
  26. used_time = float(comment.split(' ')[1][:-1])
  27. stats[engine][0] += used_time
  28. stats[engine][1] += 1
  29. node = next_node
  30. ply_nr += 1
  31.  
  32. #calculate average time used for move
  33. stats_final = {eng: stats[eng][0]/(stats[eng][1] if stats[eng][1]!= 0 else 1) for eng in stats.keys()}
  34. return(stats_final)
  35.  
  36. stats = average_time_per_move(PGN_PATH)
  37. nodes_per_move = 800
  38.  
  39. for engine in stats.keys():
  40. print(engine, nodes_per_move/stats[engine])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement