moonfish

Didactic Python Chess Engine that implements: Negamax, PeSTO’s Evaluation, Null Move, Quiescence Search, Lazy SMP.

https://github.com/luccabb/moonfish

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.0%) to scientific vocabulary

Keywords

alpha-beta-pruning chess chess-ai chess-engine minimax-algorithm python symmetric-multiprocessing uci
Last synced: 6 months ago · JSON representation ·

Repository

Didactic Python Chess Engine that implements: Negamax, PeSTO’s Evaluation, Null Move, Quiescence Search, Lazy SMP.

Basic Info
  • Host: GitHub
  • Owner: luccabb
  • License: mit
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 1.24 MB
Statistics
  • Stars: 23
  • Watchers: 3
  • Forks: 4
  • Open Issues: 2
  • Releases: 1
Topics
alpha-beta-pruning chess chess-ai chess-engine minimax-algorithm python symmetric-multiprocessing uci
Created over 4 years ago · Last pushed 6 months ago
Metadata Files
Readme License Citation Codeowners

README.md

moonfish

Moonfish Engine (~2000 Elo Rating Lichess.org)

Moonfish is a didactic Python chess engine designed to showcase parallel search algorithms and modern chess programming techniques. Built with code readability as a priority, Moonfish makes advanced concepts easily accessible providing a more approachable alternative to cpp engines.

The engine achieves approximately ~2000 Elo when playing against Lichess Stockfish bots (beats level 5 and loses to level 6) and includes comprehensive test suites including the Bratko-Kopec tactical test positions.

Quickstart

Requirements

  • Python 3.10

Installation and usage

Install the python library: shell pip install moonfish

From python: ```python $ python

import chess import moonfish board = chess.Board() moonfish.searchmove(board) Move.fromuci('g1f3') ```

You can also call the CLI, the CLI works as an UCI Compatible Engine: shell $ moonfish --mode=uci uci # <- user input id name Moonfish id author luccabb uciok

You can also run it as an API: shell moonfish --mode=api

Then send a request: shell $ curl "http://localhost:5000/?fen=rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR%20w%20KQkq%20-%200%201&depth=4&quiescence_search_depth=3&null_move=True&null_move_r=2&algorithm=alpha_beta" { "body": { "move": "e2e4" }, "headers": { "Access-Control-Allow-Headers": "Content-Type", "Access-Control-Allow-Methods": "OPTIONS,GET", "Access-Control-Allow-Origin": "*" }, "statusCode": 200 }

Features

Search Algorithms

  • Alpha-Beta Pruning - Negamax with α-β cutoffs
  • Lazy SMP - Shared memory parallel search utilizing all CPU cores
  • Layer-based Parallelization - Distributing work at specific search depths
  • Null Move Pruning - Skip moves to detect zugzwang positions
  • Quiescence Search - Extended search for tactical positions

Evaluation & Optimization

  • PeSTO Evaluation - Piece-square tables (PST) with tapered evaluation. Using Rofchade's PST.
  • Transposition Tables - Caching to avoid redundant calculations
  • Move Ordering - MVV-LVA (Most Valuable Victim - Least Valuable Attacker)
  • Syzygy Tablebase support for perfect endgame play
  • Opening Book integration (Cerebellum format)

Engine Interfaces

  • UCI Protocol - Compatible with popular chess GUIs
  • Web API - RESTful interface for online integration
  • Lichess Bot - Ready for deployment on Lichess.org

Configuration Options

| Parameter | Description | Default | Options | |-----------|-------------|---------|---------| | --mode | Engine Mode | uci | uci, api | | --algorithm | Search algorithm | alpha_beta | alpha_beta, lazy_smp, parallel_alpha_beta_layer_1 | | --depth | Search depth | 3 | 1-N | | --null-move | Whether to use null move pruning | False | True, False | | --null-mov-r | Null move reduction factor | 2 | 1-N | | --quiescence-search-depth | Max depth of quiescence search | 3 | 1-N | | --syzygy-path | Tablebase directory | None | Valid path |

Contributing

We welcome contributions, feel free to open PRs/Issues! Areas of interest: - New search algorithms - Improved evaluation functions - Time constrained search (e.g. find the best move in 40s) - Additional test positions - Github CI testing - Different evaluation functions - Neural Net integration - Performance benchmarking on different hardware - Improving caching

References

License

MIT License - see LICENSE file for details.

Owner

  • Name: luccabb
  • Login: luccabb
  • Kind: user

Citation (CITATION.cff)

cff-version: 1.2.0
message: If you use this software, please cite it as below.
title: "Moonfish: A Didactic Python Chess Engine"
authors:
  - family-names: Bertoncini
    given-names: Lucca
url: "https://github.com/luccabb/moonfish"

GitHub Events

Total
  • Watch event: 9
  • Delete event: 4
  • Push event: 11
  • Pull request event: 7
  • Create event: 5
Last Year
  • Watch event: 9
  • Delete event: 4
  • Push event: 11
  • Pull request event: 7
  • Create event: 5

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 76 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 2
  • Total maintainers: 1
pypi.org: moonfish

Moonfish is a didactic Python chess engine showcasing parallel search algorithms and modern chess programming techniques.

  • Homepage: https://github.com/luccabb/moonfish
  • Documentation: https://moonfish.readthedocs.io/
  • License: MIT License Copyright (c) 2021 luccabb Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  • Latest release: 0.0.1
    published 7 months ago
  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 76 Last month
Rankings
Dependent packages count: 8.8%
Average: 29.1%
Dependent repos count: 49.5%
Maintainers (1)
Last synced: 6 months ago

Dependencies

requirements.txt pypi
  • Flask ==2.0.2
  • Flask-Cors ==3.0.10
  • Jinja2 ==3.0.3
  • MarkupSafe ==2.0.1
  • Werkzeug ==2.0.2
  • chess ==1.7.0
  • click ==8.0.3
  • itsdangerous ==2.0.1
  • python-chess ==1.999
  • six ==1.16.0