Ejemplo n.º 1
0
def test_dpr_names():
    """Test names for dpr game"""
    base = rsgame.empty(3, 2)
    game = paygame.game_names(
        ['role'], 3, [['a', 'b']], base.all_profiles(),
        np.zeros((base.num_all_profiles, base.num_strats)))
    redgame = dpr.reduce_game(game, 2)
    expected = paygame.game_names(
        ['role'], 2, [['a', 'b']], redgame.all_profiles(),
        np.zeros((redgame.num_all_profiles, base.num_strats)))
    assert redgame == expected
Ejemplo n.º 2
0
def test_hierarchical_names():
    """Test hierarchical with names"""
    base = rsgame.empty(4, 2)
    game = paygame.game_names(
        ['role'], 4, [['a', 'b']], base.all_profiles(),
        np.zeros((base.num_all_profiles, base.num_strats)))
    redgame = hr.reduce_game(game, 2)
    expected = paygame.game_names(
        ['role'], 2, [['a', 'b']], redgame.all_profiles(),
        np.zeros((redgame.num_all_profiles, base.num_strats)))
    assert redgame == expected
Ejemplo n.º 3
0
def test_identity_names():
    """Test identity with names"""
    base = rsgame.empty(3, 2)
    game = paygame.game_names(
        ['role'], 3, [['a', 'b']], base.all_profiles(),
        np.zeros((base.num_all_profiles, base.num_strats)))
    redgame = ir.reduce_game(game)
    expected = paygame.game_names(
        ['role'], 3, [['a', 'b']], redgame.all_profiles(),
        np.zeros((redgame.num_all_profiles, base.num_strats)))
    assert redgame == expected
Ejemplo n.º 4
0
def rock_paper_scissors(win=1, loss=-1):
    """Return an instance of rock paper scissors"""
    if isinstance(win, abc.Iterable):
        win = list(win)
    else:
        win = [win] * 3
    if isinstance(loss, abc.Iterable):
        loss = list(loss)
    else:
        loss = [loss] * 3
    utils.check(
        all(l < 0 for l in loss) and all(w > 0 for w in win) and len(loss) == 3
        and len(win) == 3,
        'win must be greater than 0 and loss must be less than zero')
    profiles = [[2, 0, 0],
                [1, 1, 0],
                [1, 0, 1],
                [0, 2, 0],
                [0, 1, 1],
                [0, 0, 2]]
    payoffs = [[0., 0., 0.],
               [loss[0], win[0], 0.],
               [win[1], 0., loss[1]],
               [0., 0., 0.],
               [0., loss[2], win[2]],
               [0., 0., 0.]]
    return paygame.game_names(['all'], 2, [['paper', 'rock', 'scissors']],
                              profiles, payoffs)