Skip to content

Instantly share code, notes, and snippets.

@ppaulojr
Forked from notbanker/stockfish.sh
Created March 5, 2017 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppaulojr/ce45dad0899dbd64deb37800b2773738 to your computer and use it in GitHub Desktop.
Save ppaulojr/ce45dad0899dbd64deb37800b2773738 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