shithub: moonfish

ref: c173769001b5bd4ba69ea1fe6bcb8f984165cdf6
dir: /README.md/

View raw version
<!-- moonfish is licensed under the AGPL (v3 or later) -->
<!-- copyright 2023, 2024 zamfofex -->

moonfish
===

[![builds.sr.ht status](https://builds.sr.ht/~zamfofex/moonfish/commits/main.svg)](https://builds.sr.ht/~zamfofex/moonfish/commits/main)
[![Lichess rapid rating](https://lichess-shield.vercel.app/api?username=munfish&format=rapid)](https://lichess.org/@/munfish/perf/rapid)
[![Lichess blitz rating](https://lichess-shield.vercel.app/api?username=munfish&format=blitz)](https://lichess.org/@/munfish/perf/blitz)
[![Lichess bullet rating](https://lichess-shield.vercel.app/api?username=munfish&format=bullet)](https://lichess.org/@/munfish/perf/bullet)

**moonfish** is a chess bot inspired by [sunfish], written in C rather than Python. Besides being inspired by it, moonfish doesn’t reuse any code from sunfish, and is written completely from scratch.

You may [play moonfish on Lichess]! You don’t need a Lichess account, just make sure to choose “real time” and select a fast enough time control.

[sunfish]: <https://github.com/thomasahle/sunfish>
[play moonfish on Lichess]: <https://lichess.org/?user=munfish#friend>

features
---

- simple HCE based on PSTs
- alpha/beta pruning search
- cute custom UCI TUIs
- custom Lichess integration
- threaded search

limitations
---

These are things that might be fixed eventually.

- the bot will never underpromote
- the TUI will also prevent you from underpromoting
- the TUI does not detect when the game has ended due to stalemate or checkmate
- no transposition table
- no support for `go infinite` or `go mate`
- no move name or FEN validation (may lead to potential exploits)

download
---

Pre‐compiled executables for Linux of moonfish (and its tools) may be found at <https://moonfish.neocities.org>

compiling from source
---

Building on UNIX should be easy. Make sure you have GNU `make` and a C compiler like GCC, then run the following command.

~~~
make moonfish
~~~

Conversely, you may also invoke your compiler by hand. (Feel free to replace `cc` with your compiler of choice.)

Note: If your C implementation doesn’t support pthreads, but supports C11 threads, you can pass in `-Dmoonfish_c11_threads`.

Note: If your C implementation doesn’t support threads at all, you can pass in `-Dmoonfish_no_threads`.

~~~
cc -ansi -O3 -pthread -D_POSIX_C_SOURCE=199309L -o moonfish chess.c search.c main.c
~~~

The two UCI TUIs, called “play” and “analyse”, may also be compiled.

~~~
make play analyse
~~~

usage
---

moonfish is a UCI bot, which means you can select it and use it with any UCI program (though see “limitations” above). You can invoke `./moonfish` to start its UCI interface.

However, note that moonfish comes with its own UCI TUIs, called “play” and “analyse”. You can use them with any UCI engine you’d like!

To play against a UCI bot, use `./play` followed by a time control, then the command of whichever bot you want to play against. The color of your pieces will be decided randomly.

~~~
# (start a game against Stockfish)
./play 1+0 stockfish

# (start a game against Leela)
./play 5+2 lc0

# (start a game against moonfish)
./play 15+10 ./moonfish
~~~

To analyse a game with an UCI bot, use `./analyse` followed by a FEN string (or `initial` for the starting position) in a single argument (use shell quotation marks if necessary) followed by the command of whichever bot you want to use for analysis. (Though note that moonfish currently does not have analysis capabilities.)

~~~
# (analyse a game using Stockfish)
./analyse initial stockfish

# (analyse a game using Leela)
./analyse initial lc0

# (analyse a game using Leela, showing win/draw/loss evaluation)
./analyse initial lc0 --show-wdl
~~~

compiling on Windows
---

Clone the repository, then open `moonfish.vcxproj` with Visual Studio. Support for [C11 `<threads.h>`][C11 threads in VS] is required. Only the UCI bot will be compiled, not its tools. (You may use a GUI like [cutechess] to try it.)

Beware that, as of December of 2023, Microsoft, perhaps accidentally, [removed support for C11 threads][missing C11 threads] from Visual Studio but is planning to add it back. Meanwhile, a [workaround][C11 threads workaround] is given in their community support forum.

Note that [MinGW] compilation is also supported.

[cutechess]: <https://github.com/cutechess/cutechess>
[C11 threads in VS]: <https://devblogs.microsoft.com/cppblog/c11-threads-in-visual-studio-2022-version-17-8-preview-2/>
[missing C11 threads]: <https://developercommunity.visualstudio.com/t/Missing-threadsh-in-MSVC-178/10514752>
[C11 threads workaround]: <https://developercommunity.visualstudio.com/t/Missing-threadsh-in-MSVC-178/10514752#T-N10540847>
[MinGW]: <https://mingw-w64.org>

license
---

[AGPL] ([v3 or later][GPLv3+]) © zamfofex 2023, 2024

[AGPL]: <https://gnu.org/licenses/agpl-3.0>
[GPLv3+]: <https://gnu.org/licenses/gpl-faq.html#VersionThreeOrLater>