Skip to content

This project is a Flask web application that validates chess move sequences, detects illegal moves, handles "empty" moves (marked with 'z'), and checks for threefold repetition.

Notifications You must be signed in to change notification settings

wihanga-dilantha/chess-FNN-Generator

Repository files navigation

Chess Move Validator & Repetition Checker (Flask + Python-Chess)

This project is a Flask web application that validates chess move sequences, detects illegal moves, handles "empty" moves (marked with 'z'), and checks for threefold repetition.

It uses the python-chess library and custom modules for predictions, HTML board rendering, and repetition detection.

🚀 Features

  • Enter a sequence of chess moves in SAN (Standard Algebraic Notation).
  • Detects illegal moves and reports the move number.
  • Handles special "z" marker in move sequences:
    • Stops parsing when "z" is encountered.
    • Reports that an empty move was found.
  • Stores user input in Flask session for further processing.
  • Checks for threefold repetition using a custom repetition detection function.
  • Provides multiple HTML templates for displaying results.

📂 Project Structure

. ├── app.py # Main Flask app ├── minmax.py # model-based move predictor ├── chessBoard.py # HTML chessboard generator ├── repetition.py # Threefold repetition checker ├── templates/ │ ├── index.html # Input form │ ├── legal.html # Shown when all moves are legal │ ├── repetition.html # Repetition results │ └── empty.html # (Optional) predictions page ├── static/ # (Optional) CSS/JS assets └── README.md # Documentation

⚙️ Installation & Setup

  1. Clone or download the project files.

  2. Install dependencies: pip install flask chess

    (If using prediction features, also install TensorFlow/Keras and NumPy)

  3. Run the Flask server: python app.py

  4. Open in browser: http://127.0.0.1:5000/

🖥️ Usage

  1. Navigate to the index page.
  2. Enter a sequence of chess moves (e.g., e4 e5 Nf3 Nc6).
  3. The app will:
    • Show "Move sequence is legal" if no errors are found.
    • Report illegal moves with their move number.
    • Report "Empty move found" if a 'z' is present.
  4. You can check threefold repetition at /process_repetition, which uses the last entered move sequence stored in the session.

🔬 Key Components

  • python-chess: For move validation and FEN board handling.
  • Flask session: Stores the last entered move sequence.
  • repetition.py: Custom script for detecting threefold repetition.
  • Templates:
    • index.html → Input form + error messages.
    • legal.html → Shows legal move sequences.
    • repetition.html → Shows repetition detection results.

🛠️ Future Improvements

  • Render the current board state using HTML chessboard.
  • Integrate model predictions (minmax.py + CNN model).
  • Provide top move suggestions when a "z" marker is found.
  • Add user authentication for saving move history.

📜 License

This project is open-source. Feel free to use and modify it for research or educational purposes.

About

This project is a Flask web application that validates chess move sequences, detects illegal moves, handles "empty" moves (marked with 'z'), and checks for threefold repetition.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published