예제 #1
0
def test_pick_chars(game):
    # arrange
    player1 = game.add_player('Player1')
    player2 = game.add_player('Player2')
    game.crowned_player = player2

    config = GamePlayConfig()
    config.turn_unused_faceup_chars = 2

    game_controller = GameController(game, config)
    controller1 = SpyPlayerController()
    game_controller.set_player_controller(player1, controller1)
    controller2 = SpyPlayerController()
    game_controller.set_player_controller(player2, controller2)

    game_controller.start_game()

    # act
    game_controller.start_turn()

    # assert
    # TURN-PICK
    assert player1.char is not None
    assert player2.char is not None
    # TURN-PICK-FIRST
    assert len(controller2.possible_chars) > len(controller1.possible_chars)

    # TURN-PICK-FACEDOWN
    assert len(game.turn.unused_chars) == 6

    # TURN-FACEUP
    assert sum(bool(char) for char in game.turn.unused_chars) == 2

    # TURN-FACEUP-KING
    assert Character.King not in game.turn.unused_chars
예제 #2
0
def test_destroy(game):
    # arrange
    num_districts = len(game.districts)

    player1 = game.add_player('Player1', city=[District.Manor])
    player1.cash_in(3)

    player2 = game.add_player('Player2',
                              city=[District.Docks, District.Cathedral])

    command = commands.Destroy()

    # act
    assert [
        p.name for p in command.choices(ShadowPlayer(player1, me=True),
                                        ShadowGame(player1, game))
    ] == ['Player1', 'Player2']
    command.select(player2)

    assert command.choices(ShadowPlayer(player1, me=True),
                           ShadowGame(player1, game)) == [District.Docks]
    command.select(District.Docks)

    assert not command.choices(ShadowPlayer(player1, me=True),
                               ShadowGame(player1, game))
    command.apply(player1, game)

    # assert
    assert player1.gold == 1
    assert player2.city == (District.Cathedral, )
    assert len(game.districts) == num_districts + 1
    assert game.districts[-1] == District.Docks
예제 #3
0
def test_swap_hands(game):
    # arrange
    player1 = game.add_player('Player1', hand=[District.Manor])
    player2 = game.add_player('Player2',
                              hand=[District.Tavern, District.Cathedral])

    command = commands.SwapHands()

    # act
    choices = command.choices(ShadowPlayer(player1, me=True),
                              ShadowGame(player, game))
    assert [p.name for p in choices] == ['Player2']

    command.select(player2)
    assert not command.choices(ShadowPlayer(player1, me=True),
                               ShadowGame(player, game))

    command.apply(player1, game)

    # assert
    assert player1.hand == (
        District.Tavern,
        District.Cathedral,
    )
    assert player2.hand == (District.Manor, )
예제 #4
0
def test_thief_takes_gold_from_robbed_char(game):
    # arrange
    thief = game.add_player('Player1')
    victim = game.add_player('Player2')
    victim.cash_in(10)

    game_controller = GameController(game)
    game_controller.set_player_controller(thief, DummyPlayerController())
    game_controller.set_player_controller(victim, DummyPlayerController())

    game_controller.start_game()
    game_controller.start_turn()

    thief.char = Character.Thief
    victim.char = Character.King
    game.turn.robbed_char = Character.King

    thief_gold = thief.gold
    victim_gold = victim.gold

    # act
    game_controller.take_turns()

    # assert
    turn_income = 2
    assert thief.gold == thief_gold + victim_gold + turn_income
    assert victim.gold == turn_income
예제 #5
0
def test_privates_are_not_exposed_to_bot(game):
    # arrange
    player1 = game.add_player('Player1')
    player2 = game.add_player('Player2')

    game_controller = GameController(game)
    spy_controller = SpyPlayerController()
    game_controller.set_player_controller(player1, spy_controller)
    game_controller.set_player_controller(player2, DummyPlayerController())

    game_controller.start_game()
    game_controller.start_turn()

    # act
    game_controller.take_turns()

    # assert
    game = spy_controller.game
    assert not any(bool(district) for district in game.districts)
    assert game.crowned_player in game.players
    another_player = game.players.find_by_name('Player2')
    assert not any(bool(district) for district in another_player.hand)
    assert all(bool(district)
               for district in another_player.city)  # TODO: not verifiable
    assert another_player.gold
    assert not hasattr(another_player, 'game')
예제 #6
0
def test_warlord_abilities(game):
    # arrange
    player = game.add_player('Player', char=Character.Warlord)

    victim = game.add_player('Victim', char=Character.King)
    victim.build_district(District.Docks)

    # assert
    sink = CommandsSink(player, game)
    assert not sink.possible_abilities

    sink.execute(sink.possible_actions[0])
    assert sink.possible_abilities == (commands.Destroy(), )
예제 #7
0
def test_magician_abilities(game):
    # arrange
    player = game.add_player('Player', char=Character.Magician)
    player.take_card(District.Watchtower)

    victim = game.add_player('Victim', char=Character.King)
    victim.take_card(District.Docks)

    # act
    sink = CommandsSink(player, game)

    # assert
    assert sink.possible_abilities == (commands.SwapHands(),
                                       commands.ReplaceHand())
예제 #8
0
def test_winner_with_most_score(game):
    # arrange
    player1 = game.add_player('Player1', city=[District.Watchtower] * 8)
    player2 = game.add_player('Player2', city=[District.Watchtower] * 7)

    game_controller = GameController(game)

    game.turn.first_completer = player1

    # act
    winner = game_controller.winner

    # assert
    assert winner == player1
예제 #9
0
def test_player_added(game, listener):
    # arrange
    added_player = None

    def save_added_player(player):
        nonlocal added_player
        added_player = player

    listener.player_added = Mock(side_effect=save_added_player)

    # act
    game.add_player('Player1')

    # assert
    assert added_player
예제 #10
0
def test_replace_hands(game):
    # arrange
    player = game.add_player(
        'Player',
        hand=[District.Cathedral, District.Tavern, District.Cathedral])

    command = commands.ReplaceHand()

    num_districts = len(game.districts)

    # act
    assert command.choices(ShadowPlayer(player, me=True),
                           ShadowGame(player, game)) == [
                               District.Cathedral, District.Tavern,
                               District.Cathedral
                           ]

    command.select(District.Cathedral)
    assert command.choices(ShadowPlayer(player, me=True),
                           ShadowGame(player, game)) == [
                               District.Tavern, District.Cathedral
                           ]

    command.apply(player, game)

    # assert
    assert len(player.hand) == 3
    assert list(player.hand)[:2] == [District.Tavern, District.Cathedral]
    assert player.hand[2] != District.Cathedral

    assert len(game.districts) == num_districts
예제 #11
0
def test_take_turns(game):
    # arrange
    player1 = game.add_player('Player1')
    player2 = game.add_player('Player2')

    game_controller = GameController(game)
    spy_controller = SpyPlayerController()
    game_controller.set_player_controller(player1, spy_controller)
    game_controller.set_player_controller(player2, DummyPlayerController())

    game_controller.start_game()
    game_controller.start_turn()

    # act
    game_controller.take_turns()

    # assert
    assert len(spy_controller.possible_actions) == 2
예제 #12
0
def test_assassin_abilities(game):
    # arrange
    player = game.add_player('Player', char=Character.Assassin)

    # act
    sink = CommandsSink(player, game)

    # assert
    assert sink.possible_abilities == (commands.Kill(), )
예제 #13
0
def test_thief_abilities(game):
    # arrange
    player = game.add_player('Player', char=Character.Thief)

    # act
    sink = CommandsSink(player, game)

    # assert
    assert sink.possible_abilities == (commands.Rob(), )
예제 #14
0
def test_bonus_for_completing_city(game):
    # arrange
    player = game.add_player('Player', city=[District.Watchtower] * 8)

    # act
    score = rules.score(player, game)

    # assert
    bonus = 2
    assert score == 8 + bonus
예제 #15
0
def test_possible_income(game):
    # arrange
    city = [District.Prison, District.Watchtower, District.TradingPost]
    player = game.add_player('Player', char=Character.Warlord, city=city)

    # act
    sink = CommandsSink(player, game)

    # assert
    assert sink.possible_income == (commands.CashIn(2), )
예제 #16
0
def test_score_is_cost_of_the_city(game):
    # arrange
    player = game.add_player('Player',
                             city=[District.Watchtower, District.Palace])

    # act
    score = rules.score(player, game)

    # assert
    assert score == 1 + 5
예제 #17
0
def test_winner_with_most_score_without_bonuses_if_tie(game):
    # arrange
    player1 = game.add_player('Player1', city=[District.Watchtower] * 8)
    player2 = game.add_player(
        'Player2',
        city=[District.Palace, District.Cathedral, District.TradingPost])

    game_controller = GameController(game)

    game.turn.first_completer = player1

    assert rules.score(player1, game) == 12
    assert rules.score(player2, game) == 12

    # act
    winner = game_controller.winner

    # assert
    assert winner == player2
예제 #18
0
def test_possible_actions(game):
    # arrange
    player = game.add_player('Player', char=Character.King)

    # act
    sink = CommandsSink(player, game)

    # assert
    assert sink.possible_actions == (commands.CashIn(2),
                                     commands.DrawSomeCards(draw=2, keep=1))
예제 #19
0
def test_take_crown(game):
    # arrange
    player = game.add_player('Player1')
    command = commands.TakeCrown()

    # act
    command.apply(player, game)

    # assert
    assert game.crowned_player == player
예제 #20
0
def test_winner_with_most_gold_if_double_tie(game):
    # arrange
    player1 = game.add_player('Player1', city=[District.Watchtower] * 8)
    player2 = game.add_player('Player2', city=[District.Tavern] * 8)

    player1.cash_in(9)
    player2.cash_in(10)

    game_controller = GameController(game)

    assert rules.score(player1, game) == 10
    assert rules.score(player1, game, with_bonuses=False) == 8
    assert rules.score(player2, game) == 10
    assert rules.score(player2, game, with_bonuses=False) == 8

    # act
    winner = game_controller.winner

    # assert
    assert winner == player2
예제 #21
0
def test_income_may_be_taken_before_action(game):
    # arrange
    player = game.add_player('Player',
                             char=Character.Warlord,
                             city=[District.Prison])

    # act
    sink = CommandsSink(player, game)

    # assert
    assert sink.possible_income
예제 #22
0
def test_sink_is_done_when_end_turn_called(game):
    # arrange
    player = game.add_player('Player', char=Character.Assassin)

    # act
    sink = CommandsSink(player, game)
    sink.execute(sink.possible_actions[0])
    assert sink.can_end_turn
    sink.end_turn()

    # assert
    assert sink.done
예제 #23
0
def test_builds_cannot_be_made_before_action(game):
    # arrange
    player = game.add_player('Player',
                             char=Character.Warlord,
                             hand=[District.Watchtower])
    player.cash_in(10)

    # act
    sink = CommandsSink(player, game)

    # assert
    assert not sink.possible_builds
예제 #24
0
def test_income_must_be_taken_after_action(game):
    # arrange
    player = game.add_player('Player',
                             char=Character.Warlord,
                             hand=[District.Watchtower])
    player.cash_in(10)

    # act
    sink = CommandsSink(player, game)
    sink.execute(sink.possible_actions[0])

    # assert
    assert sink.possible_builds
예제 #25
0
def test_possible_build(game):
    # arrange
    player = game.add_player('Player',
                             char=Character.King,
                             hand=[District.Tavern, District.Fortress])
    player.cash_in(2)

    # assert
    sink = CommandsSink(player, game)
    assert not sink.possible_builds

    sink.execute(sink.possible_actions[0])
    assert sink.possible_builds == (commands.Build(), )
예제 #26
0
def test_killed_char_misses_turn(game):
    # arrange
    assassing = game.add_player('Player1')
    victim = game.add_player('Player2')

    game_controller = GameController(game)
    game_controller.set_player_controller(assassing, DummyPlayerController())
    game_controller.set_player_controller(
        victim, victim_controller := SpyPlayerController())

    game_controller.start_game()
    game_controller.start_turn()

    assassing.char = Character.Assassin
    victim.char = Character.King
    game.turn.killed_char = Character.King

    # act
    game_controller.take_turns()

    # assert
    assert not victim_controller.possible_actions
예제 #27
0
def test_start_game(game):
    # arrange
    player1 = game.add_player('Player1')
    player2 = game.add_player('Player2')

    game_controller = GameController(game)
    game_controller.set_player_controller(player1, DummyPlayerController())
    game_controller.set_player_controller(player2, DummyPlayerController())

    # act
    game_controller.start_game()

    # assert
    # START-CARDS
    assert len(player1.hand) == 4
    assert len(player2.hand) == 4

    # START-GOLD
    assert player1.gold == 2
    assert player2.gold == 2

    # START-CROWN
    assert game.crowned_player in (player1, player2)
예제 #28
0
def test_bonus_for_all_colors(game):
    # arrange
    player = game.add_player('Player',
                             city=[
                                 District.Watchtower, District.Tavern,
                                 District.Temple, District.Manor
                             ])

    # act
    score = rules.score(player, game)

    # assert
    bonus = 3
    assert score == 1 + 1 + 1 + 3 + bonus
예제 #29
0
def test_architect_ability(game):
    # arrange
    player = game.add_player('Player',
                             char=Character.Architect,
                             hand=[District.Watchtower])

    # act
    sink = CommandsSink(player, game)
    sink.execute(
        next(
            iter(action for action in sink.possible_actions
                 if isinstance(action, commands.CashIn))))

    # assert
    assert len(player.hand) == 3
예제 #30
0
def test_merchant_ability(game):
    # arrange
    player = game.add_player('Player', char=Character.Merchant)
    player.cash_in(1)

    # act
    sink = CommandsSink(player, game)

    draw_cards = next(
        iter(action for action in sink.possible_actions
             if isinstance(action, commands.DrawSomeCards)))
    draw_cards.select(draw_cards.choices(player, game)[0])
    sink.execute(draw_cards)

    # assert
    assert player.gold == 2