make small style modifications
add simple webpage
make small miscellaneous improvements
moonfish is a simple chess bot written in C89 (using just a few POSIX and C11 APIs).
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.
These are things that might be resolved eventually.
go depth
, go infinite
, go mate
Pre‐compiled executables for Linux of moonfish (and some of its tools) may be found at https://moonfish.neocities.org (Windows binaries are also provided.)
Contributions to moonfish are always welcome! Whether you just have thoughts to share, or you want to improve its source code, any kind of help is vastly appreciated!
Contributions (complaints, ideas, thoughts, patches, etc.) may be submitted via email to zamfofex@twdb.moe or shared in its IRC channel (#moonfish on Libera.Chat).
Compiling on UNIX (and clones) 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.)
cc -O3 -o moonfish chess.c search.c main.c -lm -pthread
By default, moonfish uses C11 <threads.h>
, but it is possible to have it use POSIX <pthread.h>
instead by passing -Dmoonfish_pthreads
to the compiler. (This is necessary if you’re on Mac OS.)
cc -O3 -Dmoonfish_pthreads -o moonfish chess.c search.c main.c -lm -pthread
It is also possible to compile moonfish without a dependency on threads by passing -Dmoonfish_no_threads
to the compiler.
cc -O3 -Dmoonfish_no_threads -o moonfish chess.c search.c main.c -lm
make analyse
“analyse” is a TUIs that allows you to analyse chess games with UCI bots.
After compiling and running it, you may use the mouse to click and move pieces around. (So, they require mouse support from your terminal.)
To analyse a game with a UCI bot, use ./analyse
followed optionally by the UCI options you want to specify, and then the command of whichever bot you want to use for analysis. (Though note that moonfish has limited analysis capabilities.)
# (analyse a game using Stockfish)
./analyse stockfish
# (analyse a game using Stockfish, showing win/draw/loss evaluation)
./analyse UCI_ShowWDL=true stockfish
# (analyse a game using Leela)
./analyse lc0
# (analyse a game using Leela, showing win/draw/loss evaluation)
./analyse lc0 --show-wdl
make chat
moonfish’s IRC integration, called “chat” may be used to play with a UCI bot through IRC. The bot will connect to a given network through TLS and then start responding to move names such as “e4” written on given channels.
# have moonfish play on a given channel
./chat -N irc.example.net -C '#my-channel' ./moonfish
# have Stockfish play on the given channels with the given nickname "chess-bot"
./chat -N irc.example.net -C '#my-channel,#other-channel' -M chess-bot stockfish
It is only possible to connect to networks using TLS. The default nickname is “moonfish”, and it will connect by default to #moonfish on Libera.Chat.
make lichess
In order to integrate a UCI bot with Lichess, it is possible to use “lichess”. Simply write ./lichess
followed by your bot’s command. The Lichess bot token may be specified with the lichess_token
environment variable.
# (use Stockfish as a Lichess bot)
lichess_token=XXX ./lichess stockfish
# (use moonfish as a Lichess bot)
lichess_token=XXX ./lichess ./moonfish
After installing NPE, each file may be compiled and linked as expected. (Note: A mkfile
isn’t provided.)
# (example for x86-64)
6c -I/sys/include/npe -Dmoonfish_pthreads chess.c search.c main.c
6l -o moonfish chess.6 search.6 main.6
moonfish
Clone the repository, then open moonfish.vcxproj
with Visual Studio. Only the UCI bot will be compiled, not its tools. (You may use a GUI like cutechess to try it.)
Note that MinGW compilation is also supported.
The only piece of functionality the moonfish depends on that is not specified entirely in C89 is clock_gettime
.
Porting moonfish to a different platform should be a matter of simply providing a “mostly C89‐compliant” environment alongside clock_gettime
. Of course, moonfish doesn’t make use of all C89 features, so it is not necessary to have features that it doesn’t use. Compiling on 9front, for example, works through NPE, which provides something close enough to C89 for moonfish to work.
AGPL (v3 or later) © zamfofex 2023, 2024