示例#1
0
def do_list(args, config):
    url = config.get('DEFAULT', 'url')
    key_file = config.get('DEFAULT', 'key_file')

    client = RPSClient(base_url=url, keyfile=key_file)
    state = client.get_state()

    print "GAMES:"
    for k, v in state.iteritems():
        creator = v['InitialID']
        players = v.get('Players')
        state = v.get('State')
        comp = v.get("Computer")
        print "%s\tplayers: %s status: %s creator: %s" % (k, players,
                                                          state.capitalize(),
                                                          creator)
        if state == "COMPLETE":
            print "  Hands Played:"
            for player, hand in v['Hands'].iteritems():
                if comp and (player != creator):
                    print "    %s: %s" % ("Computer", hand.capitalize())
                else:
                    print "    %s: %s" % (player, hand.capitalize())
            print "  Results:"
            for other_player, result in v['Results'].iteritems():
                if comp:
                    print "    %s vs %s: %s" % (creator, "Computer", result)
                else:
                    print "    %s vs %s: %s" % (creator, other_player, result)
            print ""
        else:
            print "  Hands Played:"
            for player, hand in v['Hands'].iteritems():
                print "    %s: %s" % (player, "*******")
            print ""
示例#2
0
def do_list(args, config):
    url = config.get('DEFAULT', 'url')
    key_file = config.get('DEFAULT', 'key_file')

    client = RPSClient(base_url=url, keyfile=key_file)
    state = client.get_all_store_objects()

    print "GAMES:"
    for k, v in state.iteritems():
        creator = v['InitialID']
        players = v.get('Players')
        state = v.get('State')
        comp = v.get("Computer")
        print "%s\tplayers: %s status: %s creator: %s" % (
            k, players, state.capitalize(), creator)
        if state == "COMPLETE":
            print "  Hands Played:"
            for player, hand in v['Hands'].iteritems():
                if comp and (player != creator):
                    print "    %s: %s" % ("Computer", hand.capitalize())
                else:
                    print "    %s: %s" % (player, hand.capitalize())
            print "  Results:"
            for other_player, result in v['Results'].iteritems():
                if comp:
                    print "    %s vs %s: %s" % (creator, "Computer", result)
                else:
                    print "    %s vs %s: %s" % (creator, other_player, result)
            print ""
        else:
            print "  Hands Played:"
            for player, hand in v['Hands'].iteritems():
                print "    %s: %s" % (player, "*******")
            print ""
示例#3
0
def do_play(args, config):
    name = args.name
    hand = args.hand.upper()

    url = config.get('DEFAULT', 'url')
    key_file = config.get('DEFAULT', 'key_file')

    client = RPSClient(base_url=url, keyfile=key_file)
    client.shoot(name=name, hand=hand)
    state = client.get_state()
    comp = state[name].get('Computer')
    if comp:
        username = config.get('DEFAULT', 'username')
        # Create computer/switch to computer
        hand = random.choice(['ROCK', 'PAPER', 'SCISSORS'])
        d = vars(args)
        d["username"] = "******"
        do_init(args, config)
        # Create correct client
        url = config.get('DEFAULT', 'url')
        key_file = config.get('DEFAULT', 'key_file')
        # send Computers move
        client = RPSClient(base_url=url, keyfile=key_file)
        client.shoot(name=name, hand=hand)
        # Switch back to orignal player
        d = vars(args)
        d["username"] = username
        do_init(args, config)

    if args.wait:
        client.wait_for_commit()
示例#4
0
def do_create(args, config):
    name = args.name
    players = args.players

    url = config.get('DEFAULT', 'url')
    key_file = config.get('DEFAULT', 'key_file')

    client = RPSClient(base_url=url, keyfile=key_file)
    client.create(name=name, players=players)

    if args.wait:
        client.wait_for_commit()
示例#5
0
def do_show(args, config):
    name = args.name

    url = config.get('DEFAULT', 'url')
    key_file = config.get('DEFAULT', 'key_file')

    client = RPSClient(base_url=url, keyfile=key_file)
    state = client.get_state()

    if name not in state:
        raise RPSException('no such game: {}'.format(name))

    game = state[name]

    creator = game['InitialID']
    players = game.get('Players')
    state = game.get('State')
    comp = game.get("Computer")
    print "%s\tplayers: %s status: %s creator: %s" % (name, players,
                                                      state.capitalize(),
                                                      creator)
    if state == "COMPLETE":
        print "  Hands Played:"
        for player, hand in game['Hands'].iteritems():
            if comp and (player != creator):
                print "    %s: %s" % ("Computer", hand.capitalize())
            else:
                print "    %s: %s" % (player, hand.capitalize())
        print "  Results:"
        for other_player, result in game['Results'].iteritems():
            if comp:
                print "    %s vs %s: %s" % (creator, "Computer", result)
            else:
                print "    %s vs %s: %s" % (creator, other_player, result)
    else:
        print "  Hands Played:"
        for player, hand in game['Hands'].iteritems():
            print "    %s: %s" % (player, "*******")
示例#6
0
def do_show(args, config):
    name = args.name

    url = config.get('DEFAULT', 'url')
    key_file = config.get('DEFAULT', 'key_file')

    client = RPSClient(base_url=url, keyfile=key_file)
    state = client.get_all_store_objects()

    if name not in state:
        raise RPSException('no such game: {}'.format(name))

    game = state[name]

    creator = game['InitialID']
    players = game.get('Players')
    state = game.get('State')
    comp = game.get("Computer")
    print "%s\tplayers: %s status: %s creator: %s" % (
        name, players, state.capitalize(), creator)
    if state == "COMPLETE":
        print "  Hands Played:"
        for player, hand in game['Hands'].iteritems():
            if comp and (player != creator):
                print "    %s: %s" % ("Computer", hand.capitalize())
            else:
                print "    %s: %s" % (player, hand.capitalize())
        print "  Results:"
        for other_player, result in game['Results'].iteritems():
            if comp:
                print "    %s vs %s: %s" % (creator, "Computer", result)
            else:
                print "    %s vs %s: %s" % (creator, other_player, result)
    else:
        print "  Hands Played:"
        for player, hand in game['Hands'].iteritems():
            print "    %s: %s" % (player, "*******")
示例#7
0
def do_create(args, config):
    name = args.name
    players = args.players

    url = config.get('DEFAULT', 'url')
    key_file = config.get('DEFAULT', 'key_file')

    client = RPSClient(base_url=url, keyfile=key_file)
    client.create(name=name, players=players)

    if args.wait:
        client.wait_for_commit()
示例#8
0
def do_play(args, config):
    name = args.name
    hand = args.hand.upper()

    url = config.get('DEFAULT', 'url')
    key_file = config.get('DEFAULT', 'key_file')

    client = RPSClient(base_url=url, keyfile=key_file)
    client.shoot(name=name, hand=hand)
    state = client.get_all_store_objects()
    comp = state[name].get('Computer')
    if comp:
        username = config.get('DEFAULT', 'username')
        # Create computer/switch to computer
        hand = random.choice(['ROCK', 'PAPER', 'SCISSORS'])
        d = vars(args)
        d["username"] = "******"
        do_init(args, config)
        # Create correct client
        url = config.get('DEFAULT', 'url')
        key_file = config.get('DEFAULT', 'key_file')
        # send Computers move
        client = RPSClient(base_url=url, keyfile=key_file)
        client.shoot(name=name, hand=hand)
        # Switch back to orignal player
        d = vars(args)
        d["username"] = username
        do_init(args, config)

    if args.wait:
        client.wait_for_commit()