Skip to content

vinnyho/chess-data-analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chess Game Analyzer

A Python application that analyzes chess games using the Stockfish engine to provide insights into game phases, move quality, and player aggression.

Features

  • Opening Theory: Identify opening moves that match established chess theory.
  • Move Quality: Evaluate the quality of each move based on positional impact.
  • Game Phase Analysis: Break down games into opening, middlegame, and endgame phases.
  • Position Evaluation: Provide Stockfish-based evaluations of board positions.
  • Aggression Metrics: Measure player aggression through move types and tactical patterns.

Example Output

Move Evaluation Example Win Percentage by Phase


Setup

1. Clone the Repository

git clone https://github.com/vinny-ho/chess-data-analysis.git
cd chess-data-analysis-main

2. Install Dependencies

Make sure you have Python installed. Install required packages using:

pip install -r requirements.txt

3. Run the Application

Start the Streamlit application:

streamlit run main.py

Usage

  1. Upload PGN File:

    • Upload a PGN file containing chess games from Chess.com.
  2. Enter Your Chess.com Username:

    • Provide your username to analyze your games specifically.
  3. View Analysis:

    • Insights include:
      • Opening Theory: Compare openings to established theory.
      • Move Quality: Identify mistakes, inaccuracies, and great moves.
      • Game Phase Analysis: Understand how you play across different phases of the game.
      • Position Evaluation: See Stockfish’s evaluation of key positions.
      • Aggression Metrics: Assess tactical patterns and playing style.

Metrics System

Move Quality

Moves are evaluated based on their impact on the position’s evaluation:

class MoveType(Enum):
    BLUNDER = -3.0     # Major mistake that loses significant advantage
    MISTAKE = -1.0     # Clear mistake that loses advantage
    INACCURACY = -0.5  # Small mistake that loses some advantage
    GREAT_MOVE = 1.0   # Move that gains significant advantage
    GOOD_MOVE = 0.5    # Move that gains some advantage
    BOOK_MOVE = 0      # Standard opening theory move

Aggression Score

Aggression is quantified by the nature of moves:

class AggressionMoveType(Enum):
    CAPTURE = 1.0        # Taking an opponent's piece
    RECAPTURE = 0.2      # Taking back a piece immediately after losing one
    SACRIFICE = 3.0      # Giving up material for positional advantage
    CHECK = 1.5          # Attacking the enemy king
    CENTER = 1.5         # Controlling central squares
    PROMOTION = 3.0      # Promoting a pawn
    CENTER_ATTACK = 0.3  # Attacking central squares

The aggression score identifies tactical patterns and playing styles.


Dependencies

Ensure the following packages are installed (managed via requirements.txt):

  • chess==1.11.1
  • pandas==2.2.3
  • plotly==5.24.1
  • streamlit==1.41.1

Install all dependencies with:

pip install -r requirements.txt

Libraries Used

  • Stockfish Chess Engine: For providing position evaluation.
  • Python-Chess: For handling chess PGN game data.
  • Pandas: For data manipulation and analysis.
  • Plotly: For creating visualizations.
  • Streamlit: For building web application interface.

Improvements

  • Better Phase Evaluation: Dynamic phase evaluations of opening/middlegame/endgame based on piece activation/value.
  • Better Aggression Evaluation: Add forks/pins/King safety to try and analyze playstyle better.

Contribution

Contributions are welcomed.


License

This project is licensed under the MIT License. See the LICENSE file for details.


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages