3 # This script runs a single round of the competition
11 # Copy messages to a log file
12 if [ "$BASH_ARGV" != "_worker_" ]; then
13 # Get the round number
16 round=$(ls | grep "round" | sed -e "s:round::g" | sort -n | head --lines=1)
17 if [ "$round" == "" ]; then round=0; fi
18 round=$(( $round + 1 ))
21 exec $0 "$@" _worker_ 2>&1 | tee $results_dir/round$round/run.log
25 round=$(ls | grep "round" | sed -e "s:round::g" | sort -n | head --lines=1)
28 echo "Start at $(date)"
31 if [ "$swarm_hosts" != "" ]; then
33 for h in $swarm_hosts; do
34 swarm -c "#ABSORB $h#"
36 swarm -c "#.*# cd $root_dir; mkdir -p $results_dir/round$round"
41 cd $root_dir/$agent_dir
45 info_file=$(ls $f | grep -w "info")
46 if [ "$info_file" == "" ]; then
47 echo "Skipping agent $f (missing info file)"
49 count=$(( $count + 1 ))
54 echo "Found $count agents in $agent_dir/"
58 # Add all the games to swarm
61 if [ "$agents" == "" ]; then
62 echo "No agents to run round $round with" 1>&2
63 rm -rf "$results_dir/round$round"
67 echo "Start round $round"
71 runa="$agent_dir/$a/$(head --lines=1 $agent_dir/$a/info)"
73 if [ "$a" == "$b" ]; then continue; fi
74 for ((i=1;i<=$games_per_pair;++i)); do
75 runb="$agent_dir/$b/$(head --lines=1 $agent_dir/$b/info)"
79 l="$results_dir/round$round/$f.log"
80 err="$results_dir/round$round/$f.err"
82 echo "Game #$game: $a .vs. $b ($i of $games_per_pair)"
83 if [ "$swarm_hosts" != "" ]; then
84 swarm -c "$qchess --no-graphics \"$runa\" \"$runb\" --log=$l --log=@web/current.log 2>$err" -o $f.result
86 $qchess --no-graphics "$runa" "$runb" --log=$l --log=@web/current.log 1> $f.result 2> $err
87 if [ "$(wc -l $err | awk '{print $1}')" == "0" ]; then rm $err; fi
95 if [ "$swarm_hosts" != "" ]; then
96 swarm -c "#BARRIER BLOCK#" # Wait for all games to finish
98 #Copy over log files (start before updating scores as the scp may take some time)
99 for h in "local $swarm_hosts"; do
101 if [ \"\$(hostname)\" != \"$webserver\" ]; then
102 cd $root_dir/$results_dir/round$round;
103 for i in *.log *.err; do
104 if [ \"\$(wc -l \$i | awk '{print \$1}')\" != 0 ]; then
105 scp \$i $webserver/$root_dir/$results_dir/round$round/\$i
109 swarm -c "#$h:.* \$# $cmd" # Execute once on each host
113 echo "Completed $games games with $count agents"
115 # A bash function. Yes, they do exist.
116 function update_score
118 if [ -e $agent_dir/$1/score.dat ]; then
119 score=$(tail --lines=1 $agent_dir/$1/score.dat | awk '{print $1}')
125 score=$(( $score + $3 ))
126 echo "$3 $score $2 $4 $5" >> $agent_dir/$1/score.dat
131 for f in *.result; do
132 log=round$round/$(echo $f.log | sed -e "s:.result::g")
133 white=$(echo $f | tr '_' '\t' | awk '{print $1}')
134 black=$(echo $f | tr '_' '\t' | awk '{print $2}')
135 if [ "$(cat $f)" == "white" ]; then
136 update_score $white $black $win_score WIN $log
137 update_score $black $white $loss_score LOSS $log
138 elif [ "$(cat $f)" == "black" ]; then
139 update_score $white $black $loss_score LOSS $log
140 update_score $black $white $win_score WIN $log
141 elif [ "$(cat $f)" == "DRAW" ]; then
142 update_score $white $black $draw_score DRAW $log
143 update_score $black $white $draw_score DRAW $log
145 echo "Unrecognised result \"$(cat $f)\" in $f" 1>&2
151 echo "Updated scores"
154 if [ "$swarm_hosts" != "" ]; then
155 swarm -c "#BARRIER BLOCK#"
159 echo "Finished at $(date)"