Skip to content

Instantly share code, notes, and snippets.

@shanecelis
Created February 27, 2010 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanecelis/316426 to your computer and use it in GitHub Desktop.
Save shanecelis/316426 to your computer and use it in GitHub Desktop.
#!/bin/bash
# compete
if [ $# -eq 0 ]; then
echo "usage: compete <n> <classnames(s)>" >&2;
echo " n number of rounds" >&2;
echo "creates a CSV output for the competition.">&2;
exit 2;
fi
function match()
{
local p1="${1%%.class}";
local p2="${2%%.class}";
# Uncomment to just play with the formatting.
#return 0;
output="$(java -cp . Main -text -p1 "$p1" -p2 "$p2" | tail -1)"
if [ "$output" == "Player 1 won" ]; then
return 0;
elif [ "$output" == "Player 2 won" ]; then
return 1;
elif [ "$output" == "Draw Game" ]; then
return 2;
else
echo "error: failed to decipher win/loss/draw on output: '$output'" >&2;
return 3;
fi
}
n="$1";
shift;
#echo "rounds,$n";
for p2 in "$@"; do
echo -n ",,$p2,"
done
echo
for p2 in "$@"; do
echo -n ",WIN,LOSS,DRAW"
done
echo
for p1 in "$@"; do
echo -n "$p1"
for p2 in "$@"; do
results=(0 0 0);
if [ "$p1" != "$p2" ]; then
for ((j=0; j< n; j+=1)); do
match "$p1" "$p2";
i=$?
results[i]=$((${results[$i]} + 1))
done
echo -n ",${results[0]},${results[1]},${results[2]}"
else
echo -n ",,,"
fi
done
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment