aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcompetition.py29
-rwxr-xr-xfullcompMT.sh17
2 files changed, 33 insertions, 13 deletions
diff --git a/competition.py b/competition.py
index 3a21115..7c48846 100755
--- a/competition.py
+++ b/competition.py
@@ -9,10 +9,11 @@ The script writes a competitionlog to competitions/game_p1_vs_p2.txt (with p1
and p2 replaced by their respective commands).
Options:
- -C Do not write a Competition log
- -h Help. What you're looking at
- -q Quiet. Don't print so much
- -V Do not view the competition, so don't write an html file
+ -c <file> Write the Competition log to the specified file instead of the default
+ -C Do not write a Competition log
+ -h Help. What you're looking at
+ -q Quiet. Don't print so much
+ -V Do not view the competition, so don't write an html file
"""
import os,sys,subprocess,shlex,re,time
@@ -117,13 +118,22 @@ fname=""
quiet=False
viewcompetition=True
complog=True
+logfname=None
+
+nextIsLogfname=False
if len(sys.argv)==1: #no args
fname="competition.txt"
else:
for arg in sys.argv[1:]: #skip script name
+ if nextIsLogfname:
+ logfname=arg
+ nextIsLogfname=False
+ continue
if len(arg)>1 and arg[0]=="-":
for c in arg[1:]: #skip "-"
- if c=="C":
+ if c=="c":
+ nextIsLogfname=True
+ elif c=="C":
complog=False
elif c=="h":
print(__doc__)
@@ -140,6 +150,10 @@ else:
print("Unrecognised argument '"+arg+"'; the competition file name was already given as '"+fname+"'.")
sys.exit(1)
+if nextIsLogfname:
+ print("Missing argument to -c flag")
+ sys.exit(1)
+
if fname=="-":
if not quiet: print("Getting entries from stdin.")
p1fname=""
@@ -222,7 +236,8 @@ elif not os.path.isdir("competitions"):
sys.exit(1)
try:
- logfname="competitions"+os.path.sep+"game_"+re.sub(r"[^a-zA-Z0-9 ]","",p1fname)+"_vs_"+re.sub(r"[^a-zA-Z0-9 ]","",p2fname)+".txt"
+ if logfname==None:
+ logfname="competitions"+os.path.sep+"game_"+re.sub(r"[^a-zA-Z0-9 ]","",p1fname)+"_vs_"+re.sub(r"[^a-zA-Z0-9 ]","",p2fname)+".txt"
logfile=open(logfname,mode="w")
logfile.write("P1: "+p1fname+"\nP2: "+p2fname+"\n")
except:
@@ -359,4 +374,4 @@ if viewcompetition:
#Apparently, there's a file named "gamevisuals". Bastard.
print("Error: an existing file prohibits creation of log directory 'gamevisuals'.")
sys.exit(1)
- os.system("."+os.path.sep+"viewcompetition "+logfname+" >gamevisuals"+os.path.sep+logfname[logfname.index(os.path.sep)+1:]+".html")
+ os.system("."+os.path.sep+"viewcompetition "+logfname+" >gamevisuals"+os.path.sep+"game_"+re.sub(r"[^a-zA-Z0-9 ]","",p1fname)+"_vs_"+re.sub(r"[^a-zA-Z0-9 ]","",p2fname)+".html")
diff --git a/fullcompMT.sh b/fullcompMT.sh
index 7f4084e..7bb4665 100755
--- a/fullcompMT.sh
+++ b/fullcompMT.sh
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
BINARIES="./gluon ./neutrino ./randino ./charm"
+NUMGAMES=5
if [[ ! -e competitions ]]; then
mkdir competitions || exit 1
@@ -50,7 +51,7 @@ fi
-if [[ isatty ]]; then
+if [[ -t 1 ]]; then
function green {
printf '\x1B[33m%s\x1B[0m' $1
}
@@ -67,16 +68,19 @@ for p1 in $BINARIES; do
[[ $p1 == $p2 ]] && continue
p1pretty=$(echo "$p1" | sed 's/[^a-zA-Z0-9 ]//g')
p2pretty=$(echo "$p2" | sed 's/[^a-zA-Z0-9 ]//g')
- COMPFILE="competitionstubs/game_${p1pretty}_vs_${p2pretty}.sh"
- cat >"$COMPFILE" << EOF
+ for i in $(seq 1 $NUMGAMES); do
+ FNAMEFORMAT="game_${p1pretty}_vs_${p2pretty}.$(printf '%03d' $i)"
+ COMPFILE="competitionstubs/$FNAMEFORMAT.sh"
+ CLOGFILE="competitions/$FNAMEFORMAT.txt"
+ cat >"$COMPFILE" << EOF
#!/usr/bin/env bash
-printf "%s\n%s\n" $p1 $p2 | ./competition.py -q -
+printf "%s\n%s\n" $p1 $p2 | ./competition.py -qc "$CLOGFILE" -
status=$?
if [[ \$status != 0 ]]; then
echo \$(date +"$DATE_FMT") "$p1 - $p2 : ERROR $status (0-0)" >$FIFONAME
exit 1
fi
-lastline=\$(tail -n1 "competitions/game_${p1pretty}_vs_${p2pretty}.txt")
+lastline=\$(tail -n1 "$CLOGFILE")
if [[ "\$lastline" == "P1 won" ]]; then
echo \$(date +"$DATE_FMT") $(green "$p1") "- $p2 : WIN - LOSS (3-1)" >$FIFONAME
elif [[ "\$lastline" == "P2 won" ]]; then
@@ -85,7 +89,8 @@ elif [[ "\$lastline" == "Tie" ]]; then
echo \$(date +"$DATE_FMT") "$p1" $(green -) "$p2 : TIE (1-1)" >$FIFONAME
fi
EOF
- chmod +x $COMPFILE
+ chmod +x $COMPFILE
+ done
done
done