NeoChess-Community
NeoChess is a self-learning chess engine written in Python. It uses PyTorch to build a neural network that evaluates chess positions, and it learns by playing games against the Stockfish engine and itself. The core learning mechanism is based on reinforcement learning principles, where the model is rewarded for winning games and penalized for losing.
Note that this game was played with the parameter epsilon being set to inf
Community Extra
This is the first Chess-Bot of the Community.
Hello, everyone!
I'm incredibly excited to be here today to introduce something special: the very first community-driven chess bot. This isn't just a chess engine; it's a living project built by me, for us, to develop the best ChessAIs the world has ever seen.
I believe that the most powerful innovations are born from collaboration. That's why I've made this model an open platform. The training data, the architecture, and the results are all public. I encourage everyone—from seasoned programmers to passionate chess amateurs—to contribute your insights, your skills, and your creativity.
Imagine a chess AI that learns not just from millions of games, but from the collective genius of this community. Every game it plays, every mistake it corrects, and every brilliant move it discovers will be a testament to our combined effort.
This isn't just my project anymore; it's ours. Let's work together to push the boundaries of what's possible in chess and AI.
How It Works
The training process is orchestrated by the selfchess.py
script, which follows these steps:
Game Simulation: The engine plays a large number of chess games. The games are divided into three categories:
- NeoChess (as White) vs. Stockfish (as Black)
- NeoChess (as Black) vs. Stockfish (as White)
- NeoChess vs. NeoChess (self-play)
Parallel Processing: To speed up data generation, games are simulated in parallel using Python's
multiprocessing
library, utilizing available CPU cores.Move Selection:
- NeoChess: Uses a negamax search algorithm (
search
) to explore future moves. The evaluation of terminal positions in the search is provided by its neural network. - Stockfish: A standard, powerful chess engine provides the moves for the opponent.
- NeoChess: Uses a negamax search algorithm (
Data Collection: During each game, every board position (FEN string) where it is NeoChess's turn to move is stored.
Training: After a game concludes, a reward is assigned:
+10
for a win,-10
for a loss, and0
for a draw. The neural network is then trained on the collected board positions from that game. The training target for each position is weighted by the final game outcome, encouraging the model to value positions that lead to wins.Model Saving: The model's state (
chessy_model.pth
) is saved after each game. A backup (chessy_modelt-1.pth
) is also kept and updated periodically.
Model Architecture
The brain of NeoChess is a neural network (NN1
class) with the following structure:
- Embedding Layer: Converts the board's piece representation into a 64-dimensional vector space.
- Multi-Head Attention: An attention mechanism allows the model to weigh the importance of different pieces and their relationships on the board.
- Feed-Forward Network: A deep series of linear layers and ReLU activation functions process the features from the attention layer to produce a final evaluation score for the position.
Requirements
- Python 3.x
- PyTorch
python-chess
library- A UCI-compatible chess engine binary (e.g., Stockfish)
You can install the Python dependencies using pip:
pip install torch python-chess
Setup and Usage
Download Stockfish: Download the appropriate Stockfish binary for your system from the official website.
Configure the Script: Open
selfchess.py
and edit theCONFIG
dictionary at the top of the file:stockfish_path
: Set this to the absolute path of your downloaded Stockfish executable.model_path
: The name of the file to save the primary model.backup_model_path
: The name of the file for the backup model.- Adjust other parameters like
num_games
,learning_rate
, etc., as needed.
Run the Training: Execute the script from your terminal:
python selfchess.py
The script will then begin the training process, printing the status of each game and the training loss.
- Downloads last month
- 51