コード例 #1
0
ファイル: test_basics.py プロジェクト: botfights/monkeystud
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
ファイル: cli.py プロジェクト: botfights/monkeystud
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()
コード例 #3
0
ファイル: cli.py プロジェクト: botfights/monkeystud
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()