shithub: moonfish

Download patch

ref: 857edcbe3ee1e853350288b8fb3b4ea40c0ed831
parent: dc06d4fe06a11af45f9027d9d8fc8e1dbf87d726
author: zamfofex <zamfofex@twdb.moe>
date: Sun Jan 12 16:01:38 EST 2025

add basic unit tests

xxx

--- a/.build.yml
+++ b/.build.yml
@@ -21,6 +21,11 @@
     strip moonfish lichess chat
     scripts/minify.sh
 
+- check: |
+    sudo rc-service devfs start
+    cd moonfish
+    make check
+
 - deploy: |
     set +x
     
--- a/.gitignore
+++ b/.gitignore
@@ -31,3 +31,5 @@
 !/scripts/rename.sh
 !/scripts/compare.sh
 !/scripts/offload.sh
+!/scripts/check.sh
+!/scripts/check.txt
--- a/makefile
+++ b/makefile
@@ -9,7 +9,7 @@
 src = $(.ALLSRC:M*.c)
 tools = lichess analyse chat perft
 
-.PHONY: all clean install
+.PHONY: all check clean install
 
 all: moonfish lichess analyse chat
 
@@ -32,6 +32,9 @@
 
 perft: tools/perft.c
 perft: cflags =
+
+check: moonfish perft
+	scripts/check.sh
 
 clean:
 	git clean -fdx
--- /dev/null
+++ b/scripts/check.sh
@@ -1,0 +1,43 @@
+#!/usr/bin/env bash
+
+# moonfish is licensed under the AGPL (v3 or later)
+# copyright 2025 zamfofex
+
+set -eo pipefail
+
+go()
+{
+	echo 'setoption name Threads value 1'
+	echo "position fen $1"
+	echo "go nodes $2"
+	while read -r line
+	do
+		case "$line" in "bestmove "*)
+			break
+		esac
+	done
+	echo quit
+}
+
+show()
+{
+	echo "- - - POSITION $2 - - -" >&2
+	./perft -F "$3" "$1"
+	coproc go "$3" `expr "$1" '*' 4096 + 2048`
+	{ ./moonfish | tee /dev/fd/3 3> /dev/fd/3 ; } <&"${COPROC[0]}" 3>&"${COPROC[1]}"
+	echo >&2
+}
+
+for n in 0 1 2 3 4
+do
+	echo "= = = DEPTH $n = = =" >&2
+	echo >&2
+	show "$n" 1 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'
+	show "$n" 2 'r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -'
+	show "$n" 3 '8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - -'
+	show "$n" 4.1 'r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1'
+	show "$n" 4.2 'r2q1rk1/pP1p2pp/Q4n2/bbp1p3/Np6/1B3NBn/pPPP1PPP/R3K2R b KQ - 0 1'
+	show "$n" 5 'rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8'
+	show "$n" 6 'r4rk1/1pp1qppp/p1np1n2/2b1p1B1/2B1P1b1/P1NP1N2/1PP1QPPP/R4RK1 w - - 0 10'
+	echo >&2
+done | tee /dev/stderr | diff scripts/check.txt -
--- /dev/null
+++ b/scripts/check.txt
@@ -1,0 +1,105 @@
+perft 0: 1
+info depth 1 score cp -1 nodes 4352
+bestmove g1f3
+perft 0: 1
+info depth 1 score cp 85 nodes 4352
+bestmove e2a6
+perft 0: 1
+info depth 1 score cp 64 nodes 4352
+bestmove b4c4
+perft 0: 1
+info depth 1 score cp -522 nodes 4352
+bestmove d2d4
+perft 0: 1
+info depth 1 score cp -522 nodes 4352
+bestmove d7d5
+perft 0: 1
+info depth 1 score cp 577 nodes 4352
+bestmove d7c8r
+perft 0: 1
+info depth 1 score cp 20 nodes 4352
+bestmove a1d1
+perft 1: 20
+info depth 1 score cp 0 nodes 8448
+bestmove b1c3
+perft 1: 48
+info depth 1 score cp 84 nodes 8448
+bestmove e2a6
+perft 1: 14
+info depth 1 score cp 38 nodes 8448
+bestmove b4c4
+perft 1: 6
+info depth 1 score cp -111 nodes 8448
+bestmove c4c5
+perft 1: 6
+info depth 1 score cp -111 nodes 8448
+bestmove c5c4
+perft 1: 44
+info depth 1 score cp 619 nodes 8448
+bestmove d7c8r
+perft 1: 46
+info depth 1 score cp 36 nodes 8448
+bestmove c3d5
+perft 2: 400
+info depth 1 score cp 9 nodes 12544
+bestmove b1c3
+perft 2: 2039
+info depth 1 score cp 203 nodes 12544
+bestmove e2a6
+perft 2: 191
+info depth 1 score cp 38 nodes 12544
+bestmove b4c4
+perft 2: 264
+info depth 1 score cp -345 nodes 12544
+bestmove c4c5
+perft 2: 264
+info depth 1 score cp -345 nodes 12544
+bestmove c5c4
+perft 2: 1486
+info depth 1 score cp 640 nodes 12544
+bestmove d7c8r
+perft 2: 2079
+info depth 1 score cp 25 nodes 12544
+bestmove c3d5
+perft 3: 8902
+info depth 1 score cp 9 nodes 16640
+bestmove b1c3
+perft 3: 97862
+info depth 1 score cp 217 nodes 16640
+bestmove e2a6
+perft 3: 2812
+info depth 1 score cp 38 nodes 16640
+bestmove b4c4
+perft 3: 9467
+info depth 1 score cp -345 nodes 16640
+bestmove c4c5
+perft 3: 9467
+info depth 1 score cp -345 nodes 16640
+bestmove c5c4
+perft 3: 62379
+info depth 1 score cp 640 nodes 16640
+bestmove d7c8q
+perft 3: 89890
+info depth 1 score cp 161 nodes 16640
+bestmove c3d5
+perft 4: 197281
+info depth 1 score cp 19 nodes 20736
+bestmove g1f3
+perft 4: 4085603
+info depth 1 score cp 172 nodes 20736
+bestmove e2a6
+perft 4: 43238
+info depth 1 score cp 32 nodes 20736
+bestmove b4c4
+perft 4: 422333
+info depth 1 score cp -443 nodes 20736
+bestmove c4c5
+perft 4: 422333
+info depth 1 score cp -443 nodes 20736
+bestmove c5c4
+perft 4: 2103487
+info depth 1 score cp 632 nodes 20736
+bestmove d7c8r
+perft 4: 3894594
+info depth 1 score cp 164 nodes 20736
+bestmove c3d5
--