Пример #1
0
def play_some_games(num_games):
    try:
        game = Game(Deck(standard_chars()), Deck(simple_districts()))
        game_controller = GameController(game)

        bot_factory = {'R': RandomBotController, 'N': NaiveBotController}
        for i, b in enumerate(bots_spec):
            bot = game.add_player('Bot{}'.format(i + 1))
            game_controller.set_player_controller(bot, bot_factory[b]())

        scores = []
        winners = []
        for _ in range(num_games):
            while not game_controller.game_over:
                game_controller.play()

            scores.append(
                [rules.score(player, game) for player in game.players])
            winners.append(game_controller.winner.player_id)

            game_controller.end_game()

        return scores, winners

    except KeyboardInterrupt:
        return None
Пример #2
0
def test_pick_architect_if_low_on_cards(bot, game, player1):
    # arrange
    player1.cash_in(2)

    # act
    char = bot.pick_char(standard_chars(), player1, game)

    # assert
    assert char == Character.Architect
Пример #3
0
def test_pick_bishop_if_one_district_left_to_build(bot, game, player1):
    # arrange
    for _ in range(7):
        player1.build_district(District.Docks)

    # act
    char = bot.pick_char(standard_chars(), player1, game)

    # assert
    assert char == Character.Bishop
Пример #4
0
def test_pick_assassin_if_there_is_leader(bot, game, player1, player2,
                                          player3):
    # arrange
    for _ in range(6):
        player1.build_district(District.Docks)

    # act
    char = bot.pick_char(standard_chars(), player3, game)

    # assert
    assert char == Character.Assassin
Пример #5
0
def test_pick_thief_if_everybody_else_has_some_gold(bot, game, player1,
                                                    player2, player3):
    # arrange
    player1.cash_in(2)
    player2.cash_in(3)

    # act
    char = bot.pick_char(standard_chars(), player3, game)

    # assert
    assert char == Character.Thief
Пример #6
0
def main():
    parser = ArgumentParser()
    parser.add_argument('--name', type=str, default='')
    parser.add_argument('--bots', type=str, default='NRR')
    parser.add_argument('--no-color', action='store_true', default=False)
    args = parser.parse_args()

    global COLORING
    COLORING = not args.no_color
    if COLORING:
        init_colorama()

    bots = args.bots
    name = args.name

    if not name:
        name = io.dialog('Enter your name', lambda n: n.strip() != '')

    game = Game(Deck(standard_chars()), Deck(simple_districts()))
    game_controller = GameController(game)

    assert 1 <= len(bots) <= 3
    assert all(b in 'NR' for b in bots)

    player = game.add_player(name)
    game_controller.set_player_controller(player, TermPlayerController())

    game_controller.add_listener(TermGamePlayListener(player, game))

    bot_factory = {'R': RandomBotController, 'N': NaiveBotController}
    for i, b in enumerate(bots):
        bot = game.add_player('bot{}'.format(i + 1))
        game_controller.set_player_controller(bot, bot_factory[b]())

    while not game_controller.game_over:
        game_controller.play()

    print('\n----------------------\nGame over!\n')
    for player in game.players:
        print('{plr} scored {score}'.format(plr=player.name,
                                            score=rules.score(player, game)))
    print('Winner is {plr}'.format(plr=game_controller.winner.name))
Пример #7
0
def standard_chars_but(char: Character):
    return tuple(ch for ch in standard_chars() if ch != char)
Пример #8
0
def game():
    return Game(Deck(standard_chars()), Deck(simple_districts()))