- chess import chess import chess.svg import chess.pgn import asyncio from pyodide.http import open_url from js import console def draw(board, draw_text=False): if not draw_text: b_svg = chess.svg.board(board=board, size=700) pyscript.write('svg', b_svg) else: pyscript.write('svg', '') pyscript.write('text', '') for row in str(board).split('\n'): pyscript.write('text', row, append=True) pgn = open_url("/kasparov-deep-blue-1997.pgn") first_game = chess.pgn.read_game(pgn) started = False board = first_game.board() draw(board) async def watch(*args, **kwargs): global started if not started: started = True title = first_game.headers["Event"] + " - " + first_game.headers["Site"] pyscript.write('title', title) players = "White: " + first_game.headers["White"] + " | Black: " + first_game.headers["Black"] pyscript.write('players', players) for move in first_game.mainline_moves(): board.push(move) # reverse of what you might expect ... white_turn = board.turn == chess.BLACK if white_turn: turn = 'White' else: turn = 'Black' try: mv = first_game.board().san(move) except: mv = " " console.log('UCI of problem move: ' + move.uci()) pyscript.write('move', turn + "'s move: " + mv) draw(board) await asyncio.sleep(3)

Chess Match Viewer


How about a nice game of chess?




            

 


 


 






Made in Python



With PyScript and Python-Chess