#! /pkg/gnu/bin/gawk -f
BEGIN {
MULT = 3
ofile = "rec" systime() ".html"
ofile = "/dev/stdout"
split(ENVIRON["QUERY_STRING"],temp,"&")
delay = temp[1]
if (!delay) delay = 4
# print "Refresh: "delay"; URL=watch3.cgi?"delay > ofile
# print "Pragma: no-cache" > ofile
print "Content-type: text/html\n" > ofile
# some browsers don't read their http!
print "" > ofile
while (getline < "payoffs")
if ($1 == "(1)") {
rows = ++nrows[np]
for (i=3; i<=NF; i++) {
utils[np,nrows[np],i-2] = $i
if (high[np]=="" || $i > high[np]) high[np] = $i
}
} else if ($0 ~ /payoffs/) ++np
cols = NF-2
if (0) print rows"x"cols > ofile
forcemade = 0
while (getline < "offers") {
if ($0 ~ /final row, final col/) { force[1]=$6; force[2]=$7 }
if ($1 ~ /1/) who = 1; else who = 2
if ($2 ~ /prop/ && kosher($3,$4) && !forcemade) {
off[who,$3,$4] = 1
if (off[not(who),$3,$4]) { finalr=$3; finalc=$4; break }
}
if ($2 ~ /force/ && (kosher($3,1)||kosher(1,$4))) {
if (!forcemade) firstforce = who
force[who] = (who==1)?$3:$4
forcemade = 1
}
if ($2 ~ /accept/ && off[not(who),$3,$4] && !forcemade) {
finalr=$3; finalc=$4; break
}
if (force[1] && force[2] && kosher(force[1],force[2])) { finalr=force[1]; finalc=force[2]; break }
}
close("offers")
getline player1 < "players"
getline player2 < "players"
getline startsystime < "players"
print "
"strftime("%M:%S",systime() - startsystime)"
" > ofile
print "" > ofile
left(); right()
print "
" > ofile
print "" > ofile
print "" > ofile
print "" > ofile
print "1. " > ofile
while (getline < "player1.peek") print > ofile
print "" > ofile
print "
" > ofile
print "" > ofile
print "" > ofile
print "" > ofile
print "2. " > ofile
while (getline < "player2.peek") print > ofile
print "" > ofile
print "
" > ofile
close(ofile)
system("cat "ofile)
}
func right() {
print "" > ofile
}
func left() {
lmargin = 50
tmargin = 50
if (0) for (i=1; i<=MULT*100; i++)
print "`" > ofile
if (0) for (i=1; i<=MULT*100; i++)
print "|" > ofile
for (r=1; r<=rows; r++) for (c=1; c<=cols; c++) {
if (utils[1,r,c] > mymax) mymax = utils[1,r,c]
if (utils[2,r,c] > mymax) mymax = utils[2,r,c]
}
if (mymax) scale = 100/mymax; else scale = 1
for (r=1; r<=rows; r++) for (c=1; c<=cols; c++)
print "O" > ofile
batna = rows SUBSEP 1
print "+" > ofile
if (0) for (i=1; i<=mscale(utils[2,batna]); i+=10)
print "`" > ofile
if (0) for (i=1; i<=mscale(utils[1,batna]); i+=20)
print "|" > ofile
print "" > ofile
print ""utils[2,batna]"" > ofile
print ""utils[1,batna]"" > ofile
lastr = lowest[1] = high[1]
lastc = lowest[2] = high[2]
symbol = 0
if (0) print ""symbol"."lowest[1]"
"lowest[2]"" > ofile
forcemade = 0
force[1] = force[2] = 0
while (getline < "offers") {
if ($0 ~ /final row, final col/) { force[1]=$6; force[2]=$7 }
if ($1 ~ /1/) who = 1; else who = 2
if ($2 ~ /prop/ && kosher($3,$4) && !forcemade) {
print "+" > ofile
oval = utils[who,$3,$4]
if (oval < lowest[who]) {
lowest[who] = oval
++symbol
if (0) print ""symbol"."lowest[1]"
"lowest[2]"" > ofile
thisr = lowest[1]; thisc = lowest[2]
if (lastc - thisc > lastr - thisr) {
for (i=0; i<=lastc-thisc; i+=2) {
slope = (lastr-thisr)/den(lastc-thisc)
print ""symbol"" > ofile
}
} else {
for (i=0; i<=lastr-thisr; i+=2) {
slope = (lastc-thisc)/den(lastr-thisr)
print ""symbol"" > ofile
}
}
if (1) for (i=1; i<=mscale(thisc); i+=10)
print "`" > ofile
if (1) for (i=1; i<=mscale(thisr); i+=10)
print "'" > ofile
lastr = thisr; lastc = thisc
}
off[who,$3,$4] = 1
if (off[not(who),$3,$4]) { finalr=$3; finalc=$4; break }
}
if ($2 ~ /force/ && (kosher($3,1)||kosher(1,$4))) {
force[who] = (who==1)?$3:$4
forcemade = 1
}
if ($2 ~ /accept/ && off[not(who),$3,$4] && !forcemade) {
if (kosher($3,$4)) print "+" > ofile
finalr=$3; finalc=$4; break
}
if (force[1] && force[2] && kosher(force[1],force[2])) { finalr=force[1]; finalc=force[2]; break }
}
close("offers")
if (1) print ""symbol". "lowest[1]"
"lowest[2]"" > ofile
if (finalr && finalc) {
++symbol
thisr = utils[1,finalr,finalc]; thisc = utils[2,finalr,finalc]
if (lastc - thisc > lastr - thisr) {
for (i=0; i<=lastc-thisc; i+=2) {
slope = (lastr-thisr)/den(lastc-thisc)
print ""symbol"" > ofile
}
} else {
for (i=0; i<=lastr-thisr; i+=2) {
slope = (lastc-thisc)/den(lastr-thisr)
print ""symbol"" > ofile
}
}
if (1) for (i=1; i<=mscale(thisc); i+=10)
print "`" > ofile
if (1) for (i=1; i<=mscale(thisr); i+=10)
print "'" > ofile
lastr = thisr; lastc = thisc
}
}
func e(w,r,c, x) {
x = utils[w,r,c]
if (r == rows && c == 1) x = ""x
if (r == finalr && c == finalc) x = ""x
if (off[w,r,c]) return ""x""
else return x
}
func offset(w) {
if (w==1) return 2
return -2
}
func clr(w) {
if (w==1) return "FFAAAA"
if (w==2) return "AAFFAA"
if (w==3) return "FFD0D0"
if (w==4) return "D0FFD0"
}
func mscale(x) {
x *= MULT*scale
if (x > MULT*200) return MULT*100
return int(x)
}
func kosher(x,y) {
if (x < 0 || y < 0) return 0
if (x > rows || y > cols) return 0
if (x != int(x) || y != int(y)) return 0
if (x+0 != x || y+0 != y) return 0
return 1
}
func not(x) {
if (x == 1) return 2
if (x == 2) return 1
}
func abs(x) { if (x < 0) return -x; return x }
func den(x) { if (!x) return 1; return x }
func ep(x,n) {
if (n == firstforce) return ""x""
return x
}
func seq(x, tt) {
split(x,tt,"=")
return tt[1]"=
"tt[2]
}