Esempio n. 1
0
from jujitsu_library import jujitsu_server, usually_choose_treasure

# To create a server, pass in a chooser function the server should use in 
# deciding what card to play.
app = jujitsu_server(usually_choose_treasure)

# This causes the program to go into an infinite loop, waiting for players
# to connect. When they do, the server replies to them with its choice for
# which card to play.
app.run(host="0.0.0.0", port=5555, debug=True)

Esempio n. 2
0
        return min(cards_at_or_above_target)

def surrender(hand):
    """Returns the worst card in a hand. This is the lowest card that's not 1,
    if there is one. Otherwise returns 1."""
    non_one_cards = filter(lambda card: card != 1, hand)
    if any(non_one_cards):
        return min(non_one_cards)
    elif any(hand):
        return 1

def get_opponent_name(state, my_name):
    if any(state['history']):
        names = state['history'][0].keys()
        names.remove('treasure')
        names.remove(my_name)
        return names[0]

def make_sneaky_player(opponent):
    "Makes a sneaky jujitsu player, designed to beat a particular opponent"
    def sneaky_player(state, player_name):
        hand = cards(player_name, state['history'])
        opponent_name = get_opponent_name(state, player_name) or "ANONYMOUS"
        opponent_choice = opponent(state, opponent_name)
        return next_highest_card(hand, opponent_choice) or surrender(hand)
    return sneaky_player

sneak = make_sneaky_player(chris_version_of_myplayer)
server = jujitsu_server(sneak)
server.run(host="0.0.0.0", port="6789")