Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. from IPython.display import SVG, display
  4. import chess.svg
  5. import chess
  6. import chess.pgn
  7. import io
  8.  
  9. filepath = 'Downloads/lichess_camille4711_2018-07-17.pgn'
  10. filepath = 'Downloads/db.pgn'
  11. game = ""
  12. with open(filepath) as fp:  
  13.     line = fp.readline()
  14.     cnt = 1
  15.     while line:
  16.         game += line
  17.         if line.count("=Q")>=6:
  18.             pgn = io.StringIO(game)
  19.             g = chess.pgn.read_game(pgn)
  20.             b = g.board()
  21.             for move in g.main_line(): b.push(move)
  22.             if len(b.pieces(chess.QUEEN,chess.BLACK)) > 6 or len(b.pieces(chess.QUEEN,chess.WHITE)) > 6:
  23.                 print(game)
  24.         if line.startswith("1."):
  25.             game = ""
  26.         line = fp.readline()
  27.         cnt += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement