Exemple #1
0
def alldishonest_test(nplayers, num_card_values, num_cards, trials, agent=0, dishonesty_list=None, confidence_list=None, learn_list=None, verbose=False):
    print "Running an all-dishonest simulation."
    game = play_game.BSGame(nplayers, [num_cards for _ in range(num_card_values)], agent, verbose=0)
    if not dishonesty_list:
        dishonesty_list = [random.random() for _ in range(nplayers)]
    if not confidence_list:
        confidence_list = [1] * nplayers
    if not learn_list:
        learn_list = [False] * nplayers
    print "Players have dishonesty", dishonesty_list
    # print "Players have confidence", confidence_list
    apolicies = []
    for t in range(nplayers):
        apolicies.append(policy.DishonestPolicy(game, dishonesty_list[t], confidence=confidence_list[t], learn=learn_list[t]).decision)
    game.setPolicies(apolicies)
    print "Simulating..."
    simulators.allsetsimulate(game, apolicies[agent], numTrials=trials, verbose=verbose)
    print "Wins observed:", game.wins
    print "Agents have winrates of", [float(game.wins[i])/sum(game.wins) for i in range(nplayers)], '\n'
Exemple #2
0
def baseline(nplayers, num_card_values, num_cards, trials, agent=None, dishonesty_list=None, confidence_list=None, learn_list=None, verbose=False):
    print "Determining baseline using SimplePolicy agent and DishonestPolicy adversaries."
    if not dishonesty_list:
        dishonesty_list = [0.1] * nplayers
    if not confidence_list:
        confidence_list = [1] * nplayers
    if not learn_list:
        learn_list = [False] * nplayers
    for i in range(nplayers):
        if agent and agent != i: continue
        print "Simulating agent", i, "..."
        game = play_game.BSGame(nplayers, [num_cards for _ in range(num_card_values)], i, verbose=0)
        ppolicy = policy.SimplePolicy(game)
        apolicies = []
        for t in range(nplayers):
            apolicies.append(policy.DishonestPolicy(game, dishonesty_list[t], confidence=confidence_list[t], learn=learn_list[t]).decision)
        game.setPolicies(apolicies)
        simulators.allsetsimulate(game, ppolicy.decision, numTrials=trials, verbose=verbose)
        print "Wins observed:", game.wins
        print "Agent in position", i, "has a win rate of ", str(float(game.wins[i])/sum(game.wins)), '\n'
        game.resetWins()