#! /usr/bin/sh
# Script to run the program, generate its coverage information
# and move it to a directory
# Make directory to save the output
mkdir -p Temporary
GAN_Inputs=(./GAN/*.txt)
Total=${#GAN_Inputs[@]}
echo Total $Total
GAME=0
for input in "${GAN_Inputs[@]}"; do
  # Start fresh
  GAME=$(( GAME +1 ))
  echo Processing $GAME with $input
  cp -r zork Temporary/Zork$GAME
  cp $input Temporary/Zork$GAME/GanInput
  cd Temporary/Zork$GAME
  make -s
  tr -d '\15\32' < GanInput > UnixGanInput
  ./zork < UnixGanInput  &> ZorkOut.gameOut
  # Generate the coverage information
  fd -d 1 -e gcda -X gcov > /dev/null
  # Make directory to save the output
  mkdir -p ./GanCoverage/Game$GAME/
  cp UnixGanInput ./GanCoverage/Game$GAME/input
  fd -d 1 -e gcov -e gameOut -X mv {} ./GanCoverage/Game$GAME
  cd ../../
  rm -rf ./Temporary/Zork$GAME
done
rmdir Temporary
