FareesSiddiqui/CSCI4052U_Final_Project

Python

0

18 commits

updated Dec 15, 2024

See the code

README

Chess Analysis Tool with custom engine

The idea I have come up with for my final project is one I have been interested in trying to implement for quite some time. I plan on developing an analytical tool for the game of chess to help users in understanding chess positions, and different strategies. The tool will consist of three main tools:

  • Reinforcement Learning (RL) Chess Engine: For my project I would like to deviate from the traditional approaches most chess engines employ. A lot of the most powerful chess engines such as Stockfish, and Leela Chess Zero use some variation of the Monte Carlo Tree Search (MCTS) algorithm. For my project, instead of relying on traditional tree search algorithms, my engine will employ a Proximal Policy Optimization (PPO) algorithm to explore chess positions, train on past games, and learn how to evaluate positions and suggest optimal moves in a position

  • Computer Vision (CV) Board Recognition: I plan on having users who like to play traditional over the board games be able to use my tool as well, and not have to manually enter chess positions into the program. My plan is to give users the ability to point a camera at a physical chessboard, and have the system automatically process the image and construct an accurate virtual representation of the board to be analyzed.

  • Natural Language Processing/Understanding (NLP/NLU): Users will be able to ask questions like "What opening is this", "What are the next moves in this line", "What are my opponents best moves in this position", etc. The tool will answer using pre-trained Large Language Models (LLMs) such as BERT or GPT-2. The LLM will parse the users questions, and interact with the chess engine to provide customized feedback.

Basic Methodology

  • The CV component will be able to detect the position of the chessboard from an image. By segmenting the board into individial squares and recognizing pieces, the system will translate the data, into a digital board state. The program will assume that the picture of the board will always be taken from the same orientation to make parsing a little simpler, and so we can easily classify the coordinates of all squares on the board. For example, having the picture be taken from the perspective of the white pieces (white at the bottom of the image). For this part of the program I plan on using OpenCV and finetuning the YOLOv8 model to accurately identify chess pieces. Identifying squares is a lot easier, the idea is to just identify the squares as black or white, and since we have a refernce point (knowing that the picture will always be from the point of view of white) we can have the program automatically assign the correct labels to each square.

  • The NLP model will be in charge of handling all user queries, and generate feedback tailored to the users current board position. I will use a pre-trained model such as BERT or GPT-2, which should be able to interpret user input, and provide detailed analysis about the current position, possible strategies, as well as being able to tell the user about the opening that has been played and what they should play against it.

  • PPO or Proximal Policy Optimzation will be used to optimize the engine's decision making process. The Reinforcement Learning agent will be trained by playing against itself, adjusting its strategy to optimize the outcomes of chess matches (wins -> draws -> losses).

Data Representation as Vectors, Matrices, and Tensors

The chessboard and game states will be encoded as matrices of tensors, where each element of the matrix will correspond to a piece on the board or an empty square.

  • Board Representation

    • The chessboard will be represented using an $N \times N$ matrix where $N = 8$. Each square $N_{ij}$ will hold a value corresponding to the piece located on that square (e.g +1 for a white pawn, -1 for a black pawn, etc).
  • Game State

    • The state of the game, which includes the currect and previous positions as well as which players turn it is will be represented as multi-dimensional tensors. Each player will be assigned their own set of tensors.
  • NLP Vectors

    • For the NLP component, user inputs will be encoded using embedding vectors generated by pre-trained models such as BERT or GPT-2. These embedding vectors will help the model in identifying semantic information about the query, allowing it to generate accurate and meaningful responses.
  • Reinforcement Learning (PPO)

    • The Policy and Value networks of the RL engine will use deep nerual networks, where the inputs (board states) and outputs (predicted move, and evaluation of the position) will be represented as tensors.

Data Collection

  • Chess Game Databases: Publicly available chess game datasets such as the Lichess Open Database, Free Internet Chess Server (FICS) game logs, or the ChessBase Mega Database will be used to train both the engine and the opening recognition system.

  • Images of chess pieces: An online dataset containing images of chess pieces will be used to train the CV component. Public datasets such as Chessvision or Kaggle datasets could be a good starting point. Based on the performance, these can be augmented by a custom dataset that I could create as well.

FareesSiddiqui/CSCI4052U_Final_Project

Python

0

18 commits

updated Dec 15, 2024

See the code

README

Chess Analysis Tool with custom engine

The idea I have come up with for my final project is one I have been interested in trying to implement for quite some time. I plan on developing an analytical tool for the game of chess to help users in understanding chess positions, and different strategies. The tool will consist of three main tools:

  • Reinforcement Learning (RL) Chess Engine: For my project I would like to deviate from the traditional approaches most chess engines employ. A lot of the most powerful chess engines such as Stockfish, and Leela Chess Zero use some variation of the Monte Carlo Tree Search (MCTS) algorithm. For my project, instead of relying on traditional tree search algorithms, my engine will employ a Proximal Policy Optimization (PPO) algorithm to explore chess positions, train on past games, and learn how to evaluate positions and suggest optimal moves in a position

  • Computer Vision (CV) Board Recognition: I plan on having users who like to play traditional over the board games be able to use my tool as well, and not have to manually enter chess positions into the program. My plan is to give users the ability to point a camera at a physical chessboard, and have the system automatically process the image and construct an accurate virtual representation of the board to be analyzed.

  • Natural Language Processing/Understanding (NLP/NLU): Users will be able to ask questions like "What opening is this", "What are the next moves in this line", "What are my opponents best moves in this position", etc. The tool will answer using pre-trained Large Language Models (LLMs) such as BERT or GPT-2. The LLM will parse the users questions, and interact with the chess engine to provide customized feedback.

Basic Methodology

  • The CV component will be able to detect the position of the chessboard from an image. By segmenting the board into individial squares and recognizing pieces, the system will translate the data, into a digital board state. The program will assume that the picture of the board will always be taken from the same orientation to make parsing a little simpler, and so we can easily classify the coordinates of all squares on the board. For example, having the picture be taken from the perspective of the white pieces (white at the bottom of the image). For this part of the program I plan on using OpenCV and finetuning the YOLOv8 model to accurately identify chess pieces. Identifying squares is a lot easier, the idea is to just identify the squares as black or white, and since we have a refernce point (knowing that the picture will always be from the point of view of white) we can have the program automatically assign the correct labels to each square.

  • The NLP model will be in charge of handling all user queries, and generate feedback tailored to the users current board position. I will use a pre-trained model such as BERT or GPT-2, which should be able to interpret user input, and provide detailed analysis about the current position, possible strategies, as well as being able to tell the user about the opening that has been played and what they should play against it.

  • PPO or Proximal Policy Optimzation will be used to optimize the engine's decision making process. The Reinforcement Learning agent will be trained by playing against itself, adjusting its strategy to optimize the outcomes of chess matches (wins -> draws -> losses).

Data Representation as Vectors, Matrices, and Tensors

The chessboard and game states will be encoded as matrices of tensors, where each element of the matrix will correspond to a piece on the board or an empty square.

  • Board Representation

    • The chessboard will be represented using an $N \times N$ matrix where $N = 8$. Each square $N_{ij}$ will hold a value corresponding to the piece located on that square (e.g +1 for a white pawn, -1 for a black pawn, etc).
  • Game State

    • The state of the game, which includes the currect and previous positions as well as which players turn it is will be represented as multi-dimensional tensors. Each player will be assigned their own set of tensors.
  • NLP Vectors

    • For the NLP component, user inputs will be encoded using embedding vectors generated by pre-trained models such as BERT or GPT-2. These embedding vectors will help the model in identifying semantic information about the query, allowing it to generate accurate and meaningful responses.
  • Reinforcement Learning (PPO)

    • The Policy and Value networks of the RL engine will use deep nerual networks, where the inputs (board states) and outputs (predicted move, and evaluation of the position) will be represented as tensors.

Data Collection

  • Chess Game Databases: Publicly available chess game datasets such as the Lichess Open Database, Free Internet Chess Server (FICS) game logs, or the ChessBase Mega Database will be used to train both the engine and the opening recognition system.

  • Images of chess pieces: An online dataset containing images of chess pieces will be used to train the CV component. Public datasets such as Chessvision or Kaggle datasets could be a good starting point. Based on the performance, these can be augmented by a custom dataset that I could create as well.