| | --- |
| | license: cc0-1.0 |
| | --- |
| | |
| | # GambitFlow Opening Database |
| |
|
| | A curated, high-quality chess opening theory database in SQLite format, designed for chess engines and analysis tools. This dataset contains aggregated move statistics derived from thousands of recent, high-rated (2600+ ELO) grandmaster-level games. |
| |
|
| | The goal of this database is to provide a powerful, statistically-backed foundation for understanding modern opening theory, without relying on traditional, human-annotated opening books. |
| |
|
| | ## How to Use |
| |
|
| | The database is a single SQLite file (`opening_theory.db`). You can download it directly from the "Files" tab or use the `huggingface_hub` library to access it programmatically. |
| |
|
| | Here is a Python example to query the database for the starting position: |
| |
|
| | ```python |
| | import sqlite3 |
| | import json |
| | from huggingface_hub import hf_hub_download |
| | |
| | # 1. Download the database file |
| | db_path = hf_hub_download( |
| | repo_id="GambitFlow/Opening-Database", |
| | filename="opening_theory.db", |
| | repo_type="dataset" |
| | ) |
| | |
| | # 2. Connect to the database |
| | conn = sqlite3.connect(db_path) |
| | cursor = conn.cursor() |
| | |
| | # 3. Query a position (FEN) |
| | # The FEN should be "canonical" (position, turn, castling, en passant) |
| | start_fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -" |
| | |
| | cursor.execute("SELECT move_data FROM openings WHERE fen = ?", (start_fen,)) |
| | row = cursor.fetchone() |
| | |
| | if row: |
| | # 4. Parse the JSON data |
| | moves_data = json.loads(row) |
| | |
| | # Sort moves by frequency |
| | sorted_moves = sorted( |
| | moves_data.items(), |
| | key=lambda item: item['frequency'], |
| | reverse=True |
| | ) |
| | |
| | print(f"Top moves for FEN: {start_fen}\n") |
| | for move, data in sorted_moves[:5]: |
| | print(f"- Move: {move}") |
| | print(f" Frequency: {data['frequency']:,}") |
| | print(f" Avg Score: {data.get('avg_score', 0.0):.3f}\n") |
| | |
| | conn.close() |
| | ``` |
| |
|
| | ## Data Collection and Processing |
| |
|
| | This dataset was meticulously created through a multi-stage pipeline to ensure the highest quality and statistical relevance. |
| |
|
| | **1. Data Source:** |
| | The foundation of this dataset is the **Lichess Elite Database**, a filtered collection of games from high-rated players, originally curated by [Nikonoel](https://database.nikonoel.fr/). We used multiple monthly PGN files from the 2023-2024 period to capture modern theory. |
| |
|
| | **2. Filtering Criteria:** |
| | Only games meeting the following strict criteria were processed: |
| | * **Minimum ELO:** Both players had a rating of **2600 or higher**. |
| | * **Maximum Depth:** Only the first **25 moves** of each game were analyzed to focus on opening theory. |
| |
|
| | **3. Processing Pipeline:** |
| | * **Distributed Processing:** The PGN files were processed in parallel across multiple sessions to handle the large volume of games efficiently. |
| | * **Perspective-Aware Scoring:** Each move's quality was scored from the perspective of the player whose turn it was. A win scored `1.0`, a loss `0.0`, and a draw `0.5`. |
| | * **Aggregation:** For each unique board position (FEN), statistics for every move played were aggregated, including frequency and the sum of scores. |
| | * **Merging:** The databases from the distributed sessions were merged into a single master file. This process recalculated weighted averages for ELO and move scores, ensuring statistical accuracy. |
| |
|
| | ## Dataset Structure |
| |
|
| | The database contains a single table named `openings`. |
| |
|
| | **File:** `opening_theory.db` |
| | **Table:** `openings` |
| |
|
| | | Column | Type | Description | |
| | |---------------|---------|-------------------------------------------------------------| |
| | | `fen` | TEXT | The canonical board position (FEN string, Primary Key). | |
| | | `move_data` | TEXT | A JSON object containing statistics for each move played. | |
| | | `total_games` | INTEGER | The total number of times this position was seen. | |
| | | `avg_elo` | INTEGER | The average ELO of players who reached this position. | |
| |
|
| | ### `move_data` JSON Structure |
| | |
| | The `move_data` column contains a JSON string with the following structure: |
| |
|
| | ```json |
| | { |
| | "e4": { |
| | "frequency": 153944, |
| | "score_sum": 76972.0, |
| | "avg_score": 0.5 |
| | }, |
| | "d4": { |
| | "frequency": 65604, |
| | "score_sum": 32802.0, |
| | "avg_score": 0.5 |
| | } |
| | } |
| | ``` |
| | * **`frequency`**: The number of times this move was played from the given position. |
| | * **`score_sum`**: The sum of all perspective-aware scores for this move. |
| | * **`avg_score`**: The average score, calculated as `score_sum / frequency`. |
| |
|
| | ## Citation |
| |
|
| | If you use this dataset in your work, please consider citing it: |
| |
|
| | ```bibtex |
| | @dataset{gambitflow_opening_database_2024, |
| | author = {GambitFlow Project}, |
| | title = {GambitFlow Opening Database}, |
| | year = {2024}, |
| | publisher = {Hugging Face}, |
| | url = {https://huggingface.co/datasets/GambitFlow/Opening-Database} |
| | } |
| | ``` |