3 # CGI wrapper to qchess
12 form = cgi.FieldStorage()
13 client = cgi.escape(os.environ["REMOTE_ADDR"])
16 with open(client): pass
18 args = ["python", "../qchess/qchess.py", "--no-graphics", "@fifo:"+client, "@internal:AgentBishop"]
19 subprocess.Popen(args)
20 form["mode"] = "query"
22 if form["mode"] == "response":
25 fifo_out = open(client+".in", "w")
26 fifo_out.write("%d %d\n" % (x, y))
28 form["mode"] = "query"
31 if form["mode"] == "query":
32 fifo_in = open(client+".out", "r")
33 s = fifo_in.readline().strip(" \r\n")
34 while s != "SELECT?" and s != "MOVE?" and s.split(" ")[0] != "white" and s.split(" ")[0] != "black":
36 s = fifo_in.readline().strip(" \r\n")
39 form["mode"] = "response"
48 if __name__ == "__main__":
50 sys.exit(main(sys.argv))
52 print "Exception: ", e