#!/bin/bash
HOST=localhost
#HOST=icfp1.cse.ogi.edu
PORT=22001
MAXITER=600
#one min

if [ "$1" != "" ]; then
  PORT=$1
fi
if [ "$2" != "" ]; then
  HOST=$2
fi

rm *ID
read weights
robot=0
while [ "$weights" != "" ]; do
  echo "executing: java Motha $HOST $PORT $weights &" 
  java Motha $HOST $PORT $weights > "robot$robot.log" &
  let "robot=$robot+1"
  read weights
done

iter=0
terminate="no"
while [ "$terminate" == "no" ]; do
  sleep 1
  echo Iteration $iter
  let "iter=$iter+1"
  if [ $iter -ge $MAXITER ]; then
    terminate="yes"
  fi
  if [ "`ps -A|grep -i java`" == "" ]; then
    terminate="yes"
  fi
    
done
echo "Terminating test"
#Mo I think you'll love this next line:
killall java

rm ranking
for i in `/bin/ls *ID`; do
  cat $i >> ranking
  echo "adding robot id: $i"
done

#will robots rank themselves?
#create a file called RANKS

echo "Rankings:"
cat ranking
echo "--------"
echo $CLASSPATH
java genScore ranking robots

echo "zaid says these would make good robots:"
cat robots
