#!/bin/sh
# $Id: CDNAgent.java,v 1.2 2008/07/01 07:03:36 nemo Exp $
# Copyright (c) 2008, Nemo Semret.
# Nemo Semret

# Run the game 12 times.

for i in 1 2 3 4 5 6 7 8 9 10 11 12
do
    java edu.columbia.ee.e6773.CDNMaster $1 $2 > CDN-$1-$2-$i.tsv
done

# Extract total utility for each run, throw out the outliers (highest and
# lowest total utility) and compute player average utility from the rest.

grep TU CDN-$1-$2-*.tsv | \
    sort -k3 | \
    awk 'BEGIN{FS=":";}\
	{ if(NR>2){system(sprintf("cat %s", prev)); print "";} prev=$1;}' | \
    awk '(NF==4){u[$1] = u[$1] + $4; n[$1] = n[$1] + 1;} \
	(NF==3) {print}\
	END{for (i in u) {print i"\t"u[i]/n[i]"\t"n[i]}}' | \
    sort -n -k2

