Пример #1
0
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)
Пример #2
0
    for j in nice['siteids']:
        plt.plot(nice['sitemap'][j]['x'],
                 nice['sitemap'][j]['y'],
                 'k.',
                 markersize=10)
    for mineLoc in nice['mines']:
        plt.plot(nice['sitemap'][mineLoc]['x'],
                 nice['sitemap'][mineLoc]['y'],
                 'ro',
                 markersize=10)
    plt.legend(loc='best')


if __name__ == "__main__":
    with open('examples/gameplay0.txt') as f:
        handshake = readMessage(f)
        messageIn = readMessage(f)
        nice = pt.map_to_nice(messageIn['move']['state']['map'])
        R = len(nice['riverdata'])

    plt.figure()
    for turn in range(0, 5):
        gameState = ['examples/gameplay' + str(turn) + '.txt']

        # Currently the map and the gamestate are not coupled.
        # By that I mean that the state id's which are specified in the file gameplay
        # are the same as the id's for maps/sample.json only

        with open(gameState[0]) as f:
            handshake = readMessage(f)
            game = readMessage(f)
Пример #3
0
import numpy as np
import matplotlib.pyplot as plt
import puntertools as pt
from rwjson import readMessage, writeMessage, readJson


maps = ['examples/setup.sample','maps/sample.json','maps/lambda.json',\
        'maps/Sierpinski-triangle.json','maps/tube.json','maps/boston-sparse.json']

gameState = ['examples/gameplay']

with open(maps[1]) as f:
    setup = pt.map_to_nice(readJson(f))

with open(gameState[0]) as f:
    handshake = readMessage(f)
    game = readMessage(f)
    pt.update_nice(setup, game['move']['moves'])

plt.figure()
for i in range(len(setup['riverdata'])):
    if setup['riverdata'][i]['claimed'] == None:
        riverid = setup['riverdata'][i]['id']
        source, target = setup['riverdata'][riverid]['sites']
        unclaimedx = [
            setup['sitemap'][source]['x'], setup['sitemap'][target]['x']
        ]
        unclaimedy = [
            setup['sitemap'][source]['y'], setup['sitemap'][target]['y']
        ]  #
        plt.plot(unclaimedx, unclaimedy, '-b')