<jupyter_start><jupyter_text>Load PGN File<jupyter_code>## load PGN
pgnfilename = '../../data/universe/samples-pgn/pgn-00001.txt'
with open(pgnfilename) as f:
    loadedGame = chess.pgn.read_game(f)
loadedGame    
nodeEnd = loadedGame.end()
nodeEnd.board()<jupyter_output><empty_output><jupyter_text>Game<jupyter_code>loadedGame.headers["Event"]<jupyter_output><empty_output><jupyter_text>Iterate Moves and svg (TODO)<jupyter_code># board01.push_san('Nf6')
# board01.push_uci('e2e4')
board = game.board()
for move in game.mainline_moves():
    ## move -> e2e4
    board.push(move) #board.push_uci(move.uci())
print(board)

svgs = []
moves = []
for move in game.mainline_moves():
    ## move -> e2e4
    board.push(move) #board.push_uci(move.uci())
    
    moves.append(move)
    svgs.append(chess.svg.board(board=board))
    

# display(svgs[5])
#moves[4]
print(board)<jupyter_output><empty_output><jupyter_text>Nodes<jupyter_code>nodeRoot = loadedGame.game()

node1w = nodeRoot.next()
node1b = node1w.next()
node1b
node1b.san()
node1b.uci()
node1b.move
node1b.board()<jupyter_output><empty_output><jupyter_text>Game Mainline<jupyter_code># g.mainline_moves() not indexing  -> move[0] ERROR
loadedGame.mainline_moves()
# for move in g.mainline_moves():
#   print(move)<jupyter_output><empty_output><jupyter_text>Game from scratch  Moves, Recreate Game<jupyter_code>boardMoveExample = chess.Board()
moves = ['e4',]
for moveNotation in moves:
    boardMoveExample.push_san(moveNotation)
boardMoveExample
pMove = chess.Move.from_uci("e7e6")
boardMoveExample.push(pMove)
boardMoveExample<jupyter_output><empty_output><jupyter_text>Create Board from FEN Notation<jupyter_code>boardFen1 = chess.Board('1Q3bk1/5p2/2p3p1/1p1bN2p/4n2P/8/r5PK/8 b - - 1 34')
boardFen1
fenStrA = 'rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2'
boardFenA = chess.Board(fenStrA)
boardFenA
fenStrB = '1Q3bk1/5p2/2p3p1/1p1bN2p/4n2P/8/r5PK/8 b - - 1 34'
boardFenB = chess.Board(fenStrB)
boardFenB<jupyter_output><empty_output><jupyter_text>Extras  Legal Moves detection<jupyter_code># Legal moves
currentBoard = node1b.board()
legalMoves = currentBoard.legal_moves
move = chess.Move.from_uci("f1e3")
move in legalMoves<jupyter_output><empty_output><jupyter_text>Switch Color Turn<jupyter_code>## Turn
boardTurn = chess.Board('1Q3bk1/5p2/2p3p1/1p1bN2p/4n2P/8/r5PK/8 b - - 1 34')
boardTurn.turn = chess.WHITE<jupyter_output><empty_output><jupyter_text>Engine<jupyter_code>engine = chess.engine.SimpleEngine.popen_uci("../shared/stockfish_12_win_x64/stockfish_20090216_x64")
board = node1b.board()
board<jupyter_output><empty_output><jupyter_text>Best move<jupyter_code>boardCurrent = copy.deepcopy(board) 
result = engine.play(boardCurrent, chess.engine.Limit(time=0.1))
boardCurrent.push(result.move)
boardCurrent<jupyter_output><empty_output><jupyter_text>Movement analyse<jupyter_code>boardCurrentMov = copy.deepcopy(board)
boardCurrentMov
analysisResult = engine.analysis(boardCurrentMov)
for info in analysisResult:
    print(info.get("score"), info.get("pv"))
    if info.get("seldepth", 0) > 5:
        break<jupyter_output>None None
PovScore(Cp(+32), WHITE) [Move.from_uci('g1f3')]
PovScore(Cp(+42), WHITE) [Move.from_uci('g1f3'), Move.from_uci('b8c6')]
PovScore(Cp(+32), WHITE) [Move.from_uci('g1f3'), Move.from_uci('b8c6'), Move.from_uci('f1b5')]
PovScore(Cp(+34), WHITE) [Move.from_uci('g1f3'), Move.from_uci('b8c6'), Move.from_uci('f1b5'), Move.from_uci('g8f6')]
PovScore(Cp(+32), WHITE) [Move.from_uci('g1f3'), Move.from_uci('b8c6'), Move.from_uci('f1b5'), Move.from_uci('g8f6'), Move.from_uci('e1g1')]
PovScore(Cp(+32), WHITE) [Move.from_uci('g1f3'), Move.from_uci('b8c6'), Move.from_uci('f1b5'), Move.from_uci('g8f6'), Move.from_uci('e1g1'), Move.from_uci('f6e4')]
{'fraction_non_alphanumeric': 0.15820260568997607, 'fraction_numerical': 0.04679606487636267, 'mean_word_length': 7.286343612334802, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '437677', 'license': 'MIT', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1642, 'n_words': 201, 'path': 'notebooks/nb-pychess-001_intro-pychess/nb-pychess-001_intro-pychess_basics.ipynb', 'repo_name': 'chema-mengibar/data-wakes_chess', 'size': '3761'}