#!/bin/bash
# Test belofte against other engines
#
# SPDX-License-Identifier: GPL-2.0-only

tourname=`basename $0 .sh`
# timecontrol="st=5"
timecontrol="tc=40/120+2"
# timecontrol="tc=inf/120+1"
# timecontrol="tc=inf/60+0.6"
# timecontrol="tc=40/25"
# timecontrol="tc=inf depth=2"

case "$OSTYPE" in
  solaris*) cutechess=cutechess-cli; ordo=ordo
            site="`uname -noi`";;
  darwin*)  cutechess=cutechess-cli; ordo=ordo
            site="`uname -noi`";;
  linux*)   cutechess=./cutechess-cli; ordo=./ordo
            site="`uname -noi`";;
  msys*)    cutechess=/c/Program\ Files\ \(x86\)/Cute\ chess/cutechess-cli.exe
            ordo=/c/Program\ Files\ \(x86\)/Cute\ chess/ordo.exe
            site=;;
  bsd*)     cutechess=cutechess-cli; ordo=ordo
            site=;;
  *)        echo "unknown: $OSTYPE"
            exit;;
esac

if [ "${OSTYPE//[0-9.]/}" != "msys" ]; then
  if [ ! -e $cutechess ]; then
    echo "Installing $cutechess"
    ln -s ../../engines.bin/Linux-x86-64/cutechess-cli $cutechess
  fi

  if [ ! -e $ordo ]; then
    echo "Installing $ordo"
    ln -s ../../engines.bin/Linux-x86-64/ordo-linux64 $ordo
  fi
fi

echo "Chess Tournament $tourname - Time control: $timecontrol"

PROJECTPATH=$(dirname `pwd`)
CHESSPATH=$(dirname $PROJECTPATH)

if [ "${OSTYPE//[0-9.]/}" == "msys" ]; then
  export PATH=$PROJECTPATH/dist/Win32:$PATH
  export PATH=$PROJECTPATH/dist/Win64:$PATH
  export PATH=$CHESSPATH/engines.bin/Win32:$PATH
  export PATH=$CHESSPATH/engines.bin/Win64:$PATH
else
  export PATH=$PROJECTPATH/dist/Linux-x86-32:$PATH
  export PATH=$PROJECTPATH/dist/Linux-x86-64:$PATH
  export PATH=$CHESSPATH/engines.bin/Linux-x86-32:$PATH
  export PATH=$CHESSPATH/engines.bin/Linux-x86-64:$PATH
  export PATH=$CHESSPATH/belofte.builds/Linux-x86-32:$PATH
  export PATH=$CHESSPATH/belofte.builds/Linux-x86-64:$PATH
fi

export PATH=$PROJECTPATH/test:$PATH

if [ -f ${tourname}.pgn ]; then
  rm ${tourname}.pgn
fi

if [ -f "openings/8mvs_big.pgn" ]; then
  openings="-openings file=openings/8mvs_big.pgn format=pgn plies=16 -repeat"
elif [ -f "openings/drawkiller_normal.pgn" ]; then
  openings="-openings file=openings/drawkiller_normal.pgn format=pgn plies=26 -repeat"
elif [ -f "openings/gm2016.pgn" ]; then
  openings="-openings file=openings/gm2016.pgn format=pgn plies=10 -repeat"
elif [ -f "openings/kasparov_1798.pgn" ]; then
  openings="-openings file=openings/kasparov_1798.pgn format=pgn plies=8 -repeat"
else
  openings=
fi

if [ -d "$CHESSPATH/Syzygy/" ]; then
  tbconfig="-tb $CHESSPATH/Syzygy/ -tbpieces 5"
else
  tbconfig=
fi

adjunct="-resign movecount=2 score=1000 twosided=false"

# reset adjudication
adjunct=
tbconfig=
recover="restart=on -recover"

# reset openings
openings=

echo "Tournament: $0 - Time control: $timecontrol" >${tourname}.log
echo "Started with: $cutechess $@ - Openings: $openings" | tee -a ${tourname}.log
echo "Endgame/Adj.: $tbconfig $adjunct $recover" | tee -a ${tourname}.log

"$cutechess" "$@" \
-rounds 4 -games 2 \
-ratinginterval 1 \
-engine conf="Belofte next (wb)" \
-engine conf="Belofte AB Static" \
-engine conf="Belofte AB Positional" \
-engine conf="Belofte ABFS Static" \
-engine conf="Belofte ABFS Positional" \
-engine conf="Belofte ABFH Static" \
-engine conf="Belofte ABFH Positional" \
-engine conf="Belofte next 32 (wb)" \
-engine conf="Belofte next 32 (u)" \
\
-engine conf="Belofte 2.1.5 (u)" \
-engine conf="Belofte 2.1.5 (wb)" \
-engine conf="Bel 32 2.1.5 (u)" \
-engine conf="Bel 32 2.1.5 (wb)" \
-engine conf="Belofte 2.1.4 (u)" \
-engine conf="Belofte 2.1.4 (wb)" \
-engine conf="Belofte 2.1.3 (u)" \
-engine conf="Belofte 2.1.3 (wb)" \
-engine conf="Belofte 0.9.20" \
-engine conf="Belofte 0.9.19" \
-engine conf="Belofte 0.9.18" \
-engine conf="Belofte 0.9.16" \
-engine conf="Belofte 0.9.12" \
\
-engine conf="Blank 1.0.1" \
-engine conf="Blunder 1.0" \
-engine conf="Blunder 2.0" \
-engine conf="Brama" \
-engine conf="Cicada 0.1" \
-engine conf="Cinnamon 1.0" \
-engine conf="Critter 1.06a" \
-engine conf="Danasah1" \
-engine conf="DarkTemplar 0.1" \
-engine conf="Deepov 0.4.1" \
-engine conf="Dexter 1.1.1" \
-engine conf="Eire" \
-engine conf="EnkoChess 190817" \
-engine conf="EnkoChess 290818" \
-engine conf="Eubos 2.4" \
-engine conf="Fimbulwinter 5.05" \
-engine conf="HopperEngine 1.0" \
-engine conf="Hippocampe 0.4.2" \
-engine conf="Iota 0.1" \
-engine conf="Komodo 12.1.1 (lv 0)" \
-engine conf="Komodo 12.1.1 (lv 1)" \
-engine conf="Komodo 12.1.1 (lv 2)" \
-engine conf="Komodo 12.1.1 (lv 3)" \
-engine conf="Komodo 12.1.1 (lv 4)" \
-engine conf="Komodo 12.1.1 (lv 5)" \
-engine conf="Komodo 12.1.1 (lv 6)" \
-engine conf="Komodo 12.1.1 (lv 7)" \
-engine conf="Komodo 12.1.1 (lv 8)" \
-engine conf="Little Wing 0.2" \
-engine conf="Little Wing 0.3" \
-engine conf="Megalodon 1.0" \
-engine conf="MinimalChess 0.2" \
-engine conf="MinimalChess 1.0.0" \
-engine conf="Pigeon 1.5.1" \
-engine conf="Princhess 0.2.1" \
-engine conf="Princhess 0.3.0" \
-engine conf="Raven 0.30" \
-engine conf="Raven 0.40" \
-engine conf="Rustic alpha 1.1" \
-engine conf="Sachy 0.2" \
-engine conf="Samchess" \
-engine conf="Squared chess 1.0" \
-engine conf="Stockfish 14 (1500)" \
-engine conf="Stockfish 14.1 (lv 0)" \
-engine conf="Stockfish 14.1 (lv 1)" \
-engine conf="Stockfish 14.1 (lv 2)" \
-engine conf="Stockfish 14.1 (lv 3)" \
-engine conf="Stockfish 14.1 (lv 4)" \
-engine conf="Stockfish 14.1 (lv 5)" \
-engine conf="Stockfish 14.1 (lv 6)" \
-engine conf="Walleye 1.4" \
-engine conf="Weiawaga 1.2" \
-engine conf="Zahak 0.2.1" \
-engine conf="Zahak 0.3.0" \
-engine conf="Zoe 0.1" \
\
-each $timecontrol $recover \
$openings $tbconfig \
$adjunct -event "cutechess-cli Tournament $tourname" \
-site "$site" \
-pgnout ${tourname}.pgn \
-wait 500 | tee -a ${tourname}.log

echo "Chess Tournament $tourname all games played, evaluating"

"$ordo" --multi-anchors=anchors-${tourname}.csv -p ${tourname}.pgn -c ratings-${tourname}.csv \
 -s 50 -n 4 -q -J | tee -a ${tourname}.log

echo "Chess Tournament $tourname finished"

#eof

