Пример #1
0
def test_play_game_ante():
    from monkeystud import play_game, make_player
    player1 = make_player('p_1', 'p_random', False)
    history_ref = None

    def get_play(history):
        history_ref = history
        return 'C'

    player1.get_play = get_play
    player2 = make_player('p_2', 'p_random', False)


    try:
        with mock.patch('monkeystud.logging') as l:
            play_game([player1, player2], False)
    finally:
        player1.done()
        player2.done()

    antes = []
    for call in l.debug.mock_calls:
        data = call[1][0]
        if 'antes' in data:
            antes.append(int(data.split()[-1]))

    assert antes[0] < antes[-1]
    assert player1.played is True
    assert player2.played is True
Пример #2
0
def test_make_player_subprocess():
    from monkeystud import PlayerProcess
    from monkeystud import PlayerMemory
    from monkeystud import make_player

    player1 = make_player('p_1', 'p_random', False, subprocess=True)
    player2 = make_player('p_2', 'p_random', False, subprocess=False)
    player1.done()
    player2.done()

    assert isinstance(player1, PlayerProcess)
    assert isinstance(player2, PlayerMemory)
Пример #3
0
def human(obj, competitors):
    players = [
        make_player('human', 'p_human', obj.catch_exceptions, False),
    ]
    if competitors:
        for i in competitors:
            players.append(
                make_player(i, i, obj.catch_exceptions, obj.subprocess)
            )
    else:
        players.append(
            make_player(
                'computer', 'p_computer', obj.catch_exceptions, obj.subprocess
            )
        )

    winner = play_game(players, obj.catch_exceptions)
    sys.exit()
Пример #4
0
def test_play_hand_valid_argument():
    from monkeystud import play_hand, make_player
    player1 = make_player('p_1', 'p_random', False)
    history_ref = None

    def get_play(history):
        history_ref = history
        return 'Z'

    player1.get_play = get_play
    player2 = make_player('p_2', 'p_random', False)
    try:
        play_hand([player1, player2], 10, False)
    finally:
        player1.done()
        player2.done()

    assert player1.played is True
    assert player2.played is True
Пример #5
0
def tournament(obj, num_games, competitors):
    players = []
    for player_id, playername in enumerate(competitors):
        if obj.verify_players:
            if 0 != verify_player(obj.max_time, playername):
                continue
        players.append(make_player(
            chr(ord('a') + player_id), playername, obj.catch_exceptions,
            obj.subprocess
        ))
    play_tournament(num_games, players, obj.catch_exceptions)
    sys.exit()
Пример #6
0
def game(obj, competitors):
    players = []
    for player_id, playername in enumerate(competitors):
        if obj.verify_players:
            player_valid = verify_player(
                obj.max_time, playername
            )
            if 0 != player_valid:
                continue
        player = make_player(
            chr(ord('a') + player_id), playername, obj.catch_exceptions,
            obj.subprocess
        )
        players.append(player)

    winner = play_game(players, obj.catch_exceptions)

    for i in players:
        i.done()

    sys.exit()