#! /pkg/gnu/bin/gawk -f BEGIN { PESS = .01 PUN = .1 HURWICZ = .8 MEM = .25 MINPROG = 3 PROBDELAY = 5 WAKEDELAY = 3 # invoke as "echo 1 | ./neg" # suspend using ctrl-Z # kill by killing the job, e.g., kill -9 %1 # this should be a 1 or a 2 getline whoami while (getline < "payoffs") if ($1 == "(1)") { maxrows = ++nrows[np] for (i=3; i<=NF; i++) { utils[np,nrows[np],i-2] = $i if (np == whoami) if (myhighest == "" || $i > myhighest) myhighest = $i } } else if ($0 ~ /payoffs/) ++np close("payoffs") maxcols = NF-2 if (0) print maxrows"x"maxcols starttime = systime() noprogtime = 0 hernoprogtime = 0 secmylead = findsecmylead() secherlead = findsecherlead() mybest = myhighest herbest = 0 while (1) { system("sleep "WAKEDELAY) if (0) print "ppagent"PESS PUN " waking up, as player" whoami noffers = 0 for (s in myoffers) delete myoffers[s] herprogress = 0 myprogress = 0 #player2 prop 1 1 from 192.165.145.247 Wed Sep 15 15:23:42 CDT 2004 while (getline < "offers") { mentioned[$1,$2,$3,$4] = 1 offers[++noffers] = $0 r = $3; c = $4 if ($1 ~ ("player"not(whoami)) && $2 == "force") { # could check that it is legit and choose best response if (whoami == 1) mention("player"whoami,"force",bestresprow(c),".") if (whoami == 2) mention("player"whoami,"force",".",bestrespcol(r)) } if ($1 ~ ("player"whoami) && $2 == "prop") { myoffers[r,c] = 1 if (!myoffersrec[r,c]) if (!printed[r,c]) { printed[r,c]=1; print "GEE, I DON'T REMEMBER MAKING THIS OFFER!",r,c } if (utils[whoami,r,c] < mybest) { mybest = utils[whoami,r,c] noprogtime = 0 myprogress = 1 } } if ($1 !~ ("player"whoami) && $2 == "prop") { heroffers[r,c] = 1 if (utils[whoami,r,c] > herbest) { herbest = utils[whoami,r,c] herbestr = r herbestc = c } if (!seenheroffers[r,c]) { thisforme = utils[whoami,r,c] if (thisforme > thisbestforme+MINPROG) { thisbestforme = thisforme mempunish = MEM*(hernoprogtime*PUN + mempunish) herprogress = 1 hernoprogtime = 0 noprogtime = 0 } } seenheroffers[r,c] = 1 } } close("offers") print "\t\t\t"whoami,hernoprogtime if (!herprogress) hernoprogtime = hernoprogtime + WAKEDELAY if (!herprogress && !myprogress) noprogtime = noprogtime + WAKEDELAY security = utils[whoami,maxrows,1] security = .5*secmylead + .5*secherlead punish = security + hernoprogtime*PUN + mempunish # eject("punish = "punish) pbd = PESS * min0(noprogtime - PROBDELAY) if (pbd > 1) pbd = 1 accexpect = HURWICZ*mybest + (1-HURWICZ)*max(herbest,security) # eject("accexpect = "accexpect) currentexpect = pbd*(.5*security + .5*punish) + (1-pbd)*accexpect # eject("currentexpect = "currentexpect) ofile = "player"whoami".peek" print "mempunish="myround(mempunish) > ofile print "hernoprogtime="myround(hernoprogtime) > ofile print "noprogtime="myround(noprogtime) > ofile print "herleadsecurity="myround(secherlead) > ofile print "myleadsecurity="myround(secmylead) > ofile print "security="myround(security) > ofile print "punish="myround(punish) > ofile print "herbest="myround(herbest) > ofile print "mybest="myround(mybest) > ofile print "pbd="myround(pbd) > ofile print "accexpect="myround(accexpect) > ofile print "currentexpect="myround(currentexpect) > ofile close(ofile) system("chmod a+r "ofile) if (currentexpect < herbest && herbestr && herbestc) { mention("player"whoami,"accept",herbestr,herbestc) nomoreoffers = 1 continue } if (punish > currentexpect || punish > accexpect) { "date" | getline date close("date") if (whoami == 1) mention("player"whoami,"force",maxrows,".") else if (whoami == 2) mention("player"whoami,"force",".",1) nomoreoffers = 1 continue } madeoffer = 0 if (!nomoreoffers) for (r=1; r<=maxrows; r++) { for (c=1; c<=maxcols; c++) { if (!myoffers[r,c]) if (utils[whoami,r,c] > currentexpect) { mention("player"whoami,"prop",r,c) myoffersrec[r,c] = 1 madeoffer = 1 } } } # system("sleep "WAKEDELAY) } } func mention(a,b,c,d) { if (mentioned[a,b,c,d]) return "date" | getline date close("date") print a,b,c,d"\tfrom ppagent "date"\t"systime() >> "offers" eject("ppagent"PESS PUN" "toupper(b)" "c" "d) close("offers") } func eject(x) { if (whoami == 1) print "\t"x if (whoami == 2) print "\t\t"x } func not(x) { if (x==1) return 2 if (x==2) return 1 } func bestresprow(c, ri,bestri,bestu) { for (ri=1; ri<=maxrows; ri++) { if (bestu=="" || utils[whoami,ri,c] > bestu) { bestu = utils[whoami,ri,c] bestri = ri } } return bestri } func bestrespcol(r, ci,bestci,bestu) { for (ci=1; ci<=maxcols; ci++) { if (bestu=="" || utils[whoami,r,ci] > bestu) { bestu = utils[whoami,r,ci] bestci = ci } } return bestci } func min0(x) { if (x < 0) return 0 return x } func myround(x) { return x return int(x*10)/10 } func max(x,y) { if (x > y) return x return y } func findsecmylead( rr,cc,herbestcc,herbestrr,herbestu,mybestu) { mybestu = "" if (whoami == 1) { for (rr=1; rr<=maxrows; rr++) { herbestcc = "" herbestu = "" for (cc=1; cc<=maxcols; cc++) { if (herbestu=="" || utils[not(whoami),rr,cc] > herbestu) { herbestu = utils[not(whoami),rr,cc] herbestcc = cc } } print "my "utils[whoami,rr,herbestcc],utils[not(whoami),rr,herbestcc] if (mybestu=="" || utils[whoami,rr,herbestcc] > mybestu) mybestu = utils[whoami,rr,herbestcc] } } else { for (cc=1; cc<=maxcols; cc++) { herbestrr = "" herbestu = "" for (rr=1; rr<=maxrows; rr++) { if (herbestu=="" || utils[not(whoami),rr,cc] > herbestu) { herbestu = utils[not(whoami),rr,cc] herbestrr = rr } } print "my "utils[whoami,herbestrr,cc], utils[not(whoami),herbestrr,cc] if (mybestu=="" || utils[whoami,herbestrr,cc] > mybestu) mybestu = utils[whoami,herbestrr,cc] } } print mybestu return mybestu } func findsecherlead( rr,cc,mybestcc,mybestrr,mybestu,herbestu) { herbestu = "" if (whoami == 2) { for (rr=1; rr<=maxrows; rr++) { mybestcc = "" mybestu = "" for (cc=1; cc<=maxcols; cc++) { if (mybestu=="" || utils[whoami,rr,cc] > mybestu) { mybestu = utils[whoami,rr,cc] mybestcc = cc } } print "her "utils[whoami,rr,mybestcc], utils[not(whoami),rr,mybestcc] if (herbestu=="" || utils[not(whoami),rr,mybestcc] > herbestu) herbestu = utils[not(whoami),rr,mybestcc] } } else { for (cc=1; cc<=maxcols; cc++) { mybestrr = "" mybestu = "" for (rr=1; rr<=maxrows; rr++) { if (mybestu=="" || utils[whoami,rr,cc] > mybestu) { mybestu = utils[whoami,rr,cc] mybestrr = rr } } print "her "utils[whoami,mybestrr,cc], utils[not(whoami),mybestrr,cc] if (herbestu=="" || utils[not(whoami),hisbestrr,cc] > herbestu) herbestu = utils[not(whoami),mybestrr,cc] } } print herbestu return herbestu }