Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Script for running two othello programs agianst eachother
- # Usage: othellostart white_player black_player time_limit
- # The time limit is in seconds
- # Author: Henrik Björklund
- # Edited by Ola Ringdahl
- if [ $# -lt 3 ]; then
- echo "Too few arguments."
- echo "Usage: othellostart white_player black_player time_limit"
- exit 1
- fi
- pos="WEEEEEEEEEEEEEEEEEEEEEEEEEEEOXEEEEEEXOEEEEEEEEEEEEEEEEEEEEEEEEEEE"
- white="$1" # the program playing white
- black="$2" # the program playing black
- time="$3" # timelimit
- endgame="no"
- whitepass="no"
- blackpass="no"
- tomove="black"
- nMoves=0
- whiteTmax=0
- blackTmax=0
- whiteTtot=0
- blackTtot=0
- declare -a moves
- index=0;
- # Play a full game
- while [ "$endgame" != "yes" ]
- do
- STARTTIME=$(date +%s)
- move=`$white $pos $time 0`
- ENDTIME=$(date +%s)
- moves[index]="$move"
- let "index += 1"
- pos=`java Mover "$pos" "$move"`
- if [ "$move" == "pass" ]
- then
- whitepass="yes"
- if [ "$blackpass" == "yes" ]
- then
- endgame="yes"
- fi
- else
- whitepass="no"
- fi
- whiteT=$(($ENDTIME - $STARTTIME))
- whiteTtot=$(($whiteTtot + $whiteT))
- if [ "$whiteT" -gt "$whiteTmax" ]
- then
- whiteTmax=$whiteT
- fi
- if [ "$endgame" != "yes" ]
- then
- STARTTIME=$(date +%s)
- move=`$black $pos $time 0`
- ENDTIME=$(date +%s)
- moves[index]="$move"
- let "index += 1"
- pos=`java Mover "$pos" "$move"`
- if [ "$move" == "pass" ]
- then
- blackpass="yes"
- if [ "$whitepass" == "yes" ]
- then
- endgame="yes"
- fi
- else
- blackpass="no"
- fi
- blackT=$(($ENDTIME - $STARTTIME))
- blackTtot=$(($blackTtot + $blackT))
- if [ "$blackT" -gt "$blackTmax" ]
- then
- blackTmax=$blackT
- fi
- fi
- nMoves=$(($nMoves+1))
- done
- whitecount=`java Counter "$pos"`
- if [ $whitecount -gt 0 ]
- then
- winner="White"
- else
- winner="Black"
- whitecount=$((-1 * $whitecount))
- fi
- whiteTmean=$(awk "BEGIN {printf \"%.1f\", ${whiteTtot} / ${nMoves}}")
- blackTmean=$(awk "BEGIN {printf \"%.1f\", ${blackTtot} / ${nMoves}}")
- echo "***************************************"
- echo "Results for $white vs. $black:"
- echo "$winner won with $whitecount points"
- echo "Average time for white: $whiteTmean s (max: $whiteTmax s)"
- echo "Average time for black: $blackTmean s (max: $blackTmax s)"
- echo "Time Limit: $time s"
- echo "Number of Moves: $nMoves"
- # echo ${moves[@]}
- echo "***************************************"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement