def offline_call(args, inp): #print 'calling', args, 'with', inp x = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE) data = rwjson.readMessage(x.stdout) #print 'got offline handshake response', data x.stdin.write(rwjson.writeMessage({'you': data['me']})) x.stdin.write(rwjson.writeMessage(inp)) #print 'have written back to offline' return rwjson.readMessage(x.stdout)
def offline_call(args, inp): print 'calling', args, 'with', inp x = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE) data = rwjson.readMessage(x.stdout) print 'got offline handshake response', data x.stdin.write(rwjson.writeMessage({'you': data['me']})) x.stdin.write(rwjson.writeMessage(inp)) print 'have written back to offline' return rwjson.readMessage(x.stdout) s = socket.create_connection(('punter.inf.ed.ac.uk', 9002)) print "writing a handshake message" s.send(rwjson.writeMessage({"me": "Xiphon"})) print "sent handshake" data = rwjson.recvMessage(s) print "got handshake", data setup = rwjson.recvMessage(s) print 'setup is', setup x = offline_call(punter_args, setup) print 'state is', x s.send(rwjson.writeMessage(x)) print 'have sent state back!' while True: data = rwjson.recvMessage(s)
setup = readJson(f) info = pt.map_to_nice(setup) R = len(info['riverdata']) playerNum = 2 for turn in range(0, R): playerPunting = turn % playerNum with open(gameState[0]) as f: handshake = readMessage(f) randRiver = randint(0, R - 1) source, target = info['riverdata'][randRiver]['sites'] state = {"map": setup, "punter": playerPunting, "punters": playerNum} claim = { "claim": { "punter": playerPunting, "source": source, "target": target } } moves = [claim] move = {"move": {"state": state, "moves": moves}} with open('examples/gameplay' + str(turn) + '.txt', 'w') as f: nh = writeMessage(handshake) message = writeMessage(move) f.write(nh) f.write(message)