Skip to content

Instantly share code, notes, and snippets.

@notbanker
Last active November 24, 2019 16:03
Show Gist options
  • Save notbanker/3b87146ab0e2a4fd9740 to your computer and use it in GitHub Desktop.
Save notbanker/3b87146ab0e2a4fd9740 to your computer and use it in GitHub Desktop.
Use stockfish engine to output the position evaluation only
#!/usr/bin/env bash
# Call stockfish engine on mac and return only the evaluation score
# Usage stockfish.sh 'r1b2rk1/4qppp/2pp4/pp6/3Bn3/PB3Q1P/1PP2PP1/3R1RK1' 5 mac 12 1024
# Usage stockfish.sh 'r1b2rk1/4qppp/2pp4/pp6/3Bn3/PB3Q1P/1PP2PP1/3R1RK1' 5 mac 12 1024
# Assumes the stockfish binary is called 'stockfish_'+binary
fen=$1
seconds=${2:-3}
binary=${3:-mac}
threads=${4:-12}
memory=${5:-1024}
(
echo "setoption name Hash value $memory" ;
echo "setoption name threads value $threads" ;
echo "position fen $fen" ;
echo "go infinite";
sleep $seconds
) | ./stockfish_$binary > analysis.txt
cat analysis.txt | grep -ohE "score cp (-?[0-9]+)" | tail -1 | cut -d' ' -f3 > score.txt
cat analysis.txt | grep -ohE "score cp (-?[0-9]+)" | cut -d' ' -f3 > scores.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment