~zamfofex/moonfish

a simple chess bot (in C89)
make small style modifications
add simple webpage
make small miscellaneous improvements

clone

read-only
https://git.sr.ht/~zamfofex/moonfish
read/write
git@git.sr.ht:~zamfofex/moonfish

You can also use your local clone with git send-email.

#moonfish

builds.sr.ht status Lichess classical rating Lichess rapid rating Lichess blitz rating

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.

#table of contents

#features

  • simple evaluation based on PSTs
  • MCTS (Monte Carlo tree search)
  • cute custom UCI TUIs
  • custom Lichess integration
  • custom IRC integration

#limitations

These are things that might be resolved eventually.

  • the TUIs do not let you underpromote
  • no support for go depth, go infinite, go mate
  • no FEN validation (may lead to potential exploits)

#download

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.)

#contributing to moonfish

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).

  • Note: The IRC channel is also bridged to Discord. (Please ask on IRC for a Discord invite.)
  • Note: There is also a #moonfish-miscellany channel for general off‐topic conversations.

#compiling from source

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

#using “analyse”

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

#using “chat”

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.

#using “lichess”

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

#compiling on 9front

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

#compiling on Windows

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.

#porting moonfish

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.

#license

AGPL (v3 or later) © zamfofex 2023, 2024