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