Пример #1
0
def prob_end_spatial_tournaments(draw, strategies=strategies,
                                min_size=1, max_size=10,
                                min_prob_end=0, max_prob_end=1,
                                min_noise=0, max_noise=1,
                                min_repetitions=1, max_repetitions=20):
    """
    A hypothesis decorator to return a probabilistic ending spatial tournament.

    Parameters
    ----------
    min_size : integer
        The minimum number of strategies to include
    max_size : integer
        The maximum number of strategies to include
    min_prob_end : float
        The minimum probability of a match ending
    max_prob_end : float
        The maximum probability of a match ending
    min_noise : float
        The minimum noise value
    max_noise : float
        The maximum noise value
    min_repetitions : integer
        The minimum number of repetitions
    max_repetitions : integer
        The maximum number of repetitions
    """
    strategies = draw(strategy_lists(strategies=strategies,
                                     min_size=min_size,
                                     max_size=max_size))
    players = [s() for s in strategies]
    player_indices = list(range(len(players)))

    all_potential_edges = list(itertools.combinations(player_indices, 2))
    all_potential_edges.extend([(i, i) for i in player_indices])  # Loops
    edges = draw(lists(sampled_from(all_potential_edges), unique=True,
                       average_size=2 * len(players)))

    # Ensure all players/nodes are connected:
    node_indices = sorted(set([node for edge in edges for node in edge]))
    missing_nodes = [index
                     for index in player_indices if index not in node_indices]
    for index in missing_nodes:
        opponent = draw(sampled_from(player_indices))
        edges.append((index, opponent))

    prob_end = draw(floats(min_value=min_prob_end, max_value=max_prob_end))
    repetitions = draw(integers(min_value=min_repetitions,
                                max_value=max_repetitions))
    noise = draw(floats(min_value=min_noise, max_value=max_noise))

    tournament = Tournament(players, prob_end=prob_end,
                            repetitions=repetitions,
                            noise=noise, edges=edges)
    return tournament
Пример #2
0
def tournaments(
    draw,
    strategies=short_run_time_strategies,
    min_size=1,
    max_size=10,
    min_turns=1,
    max_turns=200,
    min_noise=0,
    max_noise=1,
    min_repetitions=1,
    max_repetitions=20,
):
    """
    A hypothesis decorator to return a tournament.

    Parameters
    ----------
    min_size : integer
        The minimum number of strategies to include
    max_size : integer
        The maximum number of strategies to include
    min_turns : integer
        The minimum number of turns
    max_turns : integer
        The maximum number of turns
    min_noise : float
        The minimum noise value
    min_noise : float
        The maximum noise value
    min_repetitions : integer
        The minimum number of repetitions
    max_repetitions : integer
        The maximum number of repetitions
    """
    strategies = draw(
        strategy_lists(strategies=strategies,
                       min_size=min_size,
                       max_size=max_size))
    players = [s() for s in strategies]
    turns = draw(integers(min_value=min_turns, max_value=max_turns))
    repetitions = draw(
        integers(min_value=min_repetitions, max_value=max_repetitions))
    noise = draw(floats(min_value=min_noise, max_value=max_noise))

    tournament = Tournament(players,
                            turns=turns,
                            repetitions=repetitions,
                            noise=noise)
    return tournament
Пример #3
0
def prob_end_tournaments(
    draw,
    strategies=short_run_time_strategies,
    min_size=1,
    max_size=10,
    min_prob_end=0,
    max_prob_end=1,
    min_noise=0,
    max_noise=1,
    min_repetitions=1,
    max_repetitions=20,
):
    """
    A hypothesis decorator to return a tournament,

    Parameters
    ----------
    min_size : integer
        The minimum number of strategies to include
    max_size : integer
        The maximum number of strategies to include
    min_prob_end : float
        The minimum probability of a match ending
    max_prob_end : float
        The maximum probability of a match ending
    min_noise : float
        The minimum noise value
    max_noise : float
        The maximum noise value
    min_repetitions : integer
        The minimum number of repetitions
    max_repetitions : integer
        The maximum number of repetitions
    """
    strategies = draw(
        strategy_lists(strategies=strategies,
                       min_size=min_size,
                       max_size=max_size))
    players = [s() for s in strategies]
    prob_end = draw(floats(min_value=min_prob_end, max_value=max_prob_end))
    repetitions = draw(
        integers(min_value=min_repetitions, max_value=max_repetitions))
    noise = draw(floats(min_value=min_noise, max_value=max_noise))

    tournament = Tournament(players,
                            prob_end=prob_end,
                            repetitions=repetitions,
                            noise=noise)
    return tournament
Пример #4
0
def test_tournament_reproducibility():
    rng = RandomGenerator()
    seed = rng.random_seed_int()
    strategies = rng.choice(all_strategies, size=10)
    players1 = [Player(strategy) for strategy in strategies]
    tournament1 = Tournament(players1, seed=seed, repetitions=2)
    results1 = tournament1.play(processes=2)

    players2 = [Player(strategy) for strategy in strategies]
    tournament2 = Tournament(players2, seed=seed, repetitions=2)
    results2 = tournament2.play(processes=2)

    assert (results1.ranked_names == results2.ranked_names)
Пример #5
0
            j = random.random()
            #Let Mr Hyde and Dr Jykle compete
            #If Dr Jykle beats Mr Hyde cooperate else defect
            if h - j >= 0:
                return C
            else:
                return D


hj = DrJekyllMrHyde()  #Create instance of class

#players = [s() for s in axl.short_run_time_strategies]  # Create players
players = [
    hj,
    axl.Defector(),
    axl.TitForTat(),
    axl.Thumper(),
    axl.Punisher(),
    axl.AdaptiveTitForTat(),
    axl.FirstByDavis(),
    axl.Appeaser()
]
#players.append(hj)
tournament = Tournament(players)  # Create a tournament
results = tournament.play()  # Play the tournament

results.write_summary('SummaryMileStone3.csv')  # Write results to csv file

plot = axl.Plot(results)
p = plot.boxplot()  #Plot results
p.show()