A chess playing neural network trained on expert games from the Lichess Elite Database.
This is a policy-value network inspired by AlphaZero, designed to evaluate chess positions and suggest moves.
1import torch
2import chess
3from model import TinyPCN, encode_board
4
5# Load model
6model = TinyPCN(board_channels=18, policy_size=4672)
7model.load_state_dict(torch.load("chess_model.pth"))
8model.eval()
9
10# Evaluate a position
11board = chess.Board() # or chess.Board("fen string")
12board_tensor = encode_board(board).unsqueeze(0)
13
14with torch.no_grad():
15 policy_logits, value = model(board_tensor)
16
17# Value interpretation:
18# +1.0 = winning for current player
19# 0.0 = drawn/equal position
20# -1.0 = losing for current player
21
22print(f"Position evaluation: {value.item():.4f}")
Created as part of an AlphaZero-style chess engine project.