#! /usr/local/bin/tcsh -f
#
#  A script to play a connect5 match (two games).
#  Bug: error messages from conn5 are not handled very well.

if ($1 == -h || $1 == --help || $1 == -help || $#argv > 3) then
  echo "  "A script to play a connect5 match (two games).
  echo Usage: $0 \[-q\] game1 game2
  echo "  "where each gamei is either a comp210 user id, or
  echo "  "the pathname of an connect5 code \(scheme or executable\)
  echo ""
  echo "  "Bug: error messages from conn5 are not handled very well.
  exit
  endif


if ($1 == -q || $1 == --quiet) then
  set quiet = 1
  shift
else
  set quiet = 0
  endif

set noisy = (! $quiet)

set name1 = $1
set name2 = $2


set conn5 = conn5-gui
set boardSize = 15
set timeLimit = 30
set conn5flags = "-t $timeLimit -n $boardSize"
if ($quiet) set conn5flags = "-q $conn5flags"

set ex1 = /home/$name1/comp210/connect5/connect5
set ss1 = /home/$name1/comp210/connect5/connect5.ss
if (-x $ex1) then
  set prog1 = $ex1
else if (-e $ss1) then
  set prog1 = $ss1
else if (-e $name1) then
  set prog1 = $name1
else
  echo file not found for $name1
  exit
  endif

set ex2 = /home/$name2/comp210/connect5/connect5
set ss2 = /home/$name2/comp210/connect5/connect5.ss
if (-x $ex2) then
  set prog2 = $ex2
else if (-e $ss2) then
  set prog2 = $ss2
else if (-e $name2) then
  set prog2 = $name2
else
  echo file not found for $name2
  exit
  endif




if ($noisy) echo $name1 versus $name2

if ($noisy) echo -n "  " $name1 moves first...
set runConn5 = "$conn5 $conn5flags -p1 $prog1 -p2 $prog2"
$runConn5

if ($noisy) echo -n "  " now $name2 moves first...
set runConn5 = "$conn5 $conn5flags -p1 $prog2 -p2 $prog1"
$runConn5
