Ejemplo n.º 1
0
 def take_turn(self, player: Player, game: Game, sink: CommandsSink):
     self.game = game
     if not self.possible_actions:
         self.possible_actions = list(sink.possible_actions)
     if sink.possible_actions:
         sink.execute(sink.possible_actions[0])
     else:
         sink.end_turn()
Ejemplo n.º 2
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(), )
Ejemplo n.º 3
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(), )
Ejemplo n.º 4
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
Ejemplo n.º 5
0
    def take_turn(self, player: Player, game: Game, sink: CommandsSink):
        """ Should execute commands via sink """
        command = random.choice(list(sink.all_possible_commands))

        if isinstance(command, InteractiveCommand):
            while command.choices(player, game):
                command.select(random.choice(command.choices(player, game)))
            assert command.ready

        if command:
            sink.execute(command)
        else:
            sink.end_turn()
Ejemplo n.º 6
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
Ejemplo n.º 7
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
Ejemplo n.º 8
0
def test_action_is_cash_in_if_low_on_gold(bot, game, king):
    # act
    sink = CommandsSink(king, game)
    command = bot.decide(king, game, sink)

    # assert
    assert isinstance(command, commands.CashIn)
Ejemplo n.º 9
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(), )
Ejemplo n.º 10
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(), )
Ejemplo n.º 11
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))
Ejemplo n.º 12
0
def test_destroy_lead_player_district(bot, game, warlord, king, thief):
    # arrange
    for _ in range(6):
        king.build_district(District.Docks)

    for _ in range(7):
        thief.build_district(District.Docks)

    context = bot.create_context(warlord, game)

    sink = CommandsSink(warlord, game)
    sink.execute(sink.possible_actions[0])
    assert sink.possible_abilities

    # act
    command = bot.destroy(sink.possible_abilities, context, warlord, game)

    # assert
    assert command == commands.Destroy(target=thief, card=District.Docks)
Ejemplo n.º 13
0
def test_action_is_draw_cards_if_high_on_gold(bot, game, king):
    # arrange
    king.cash_in(6)

    # act
    sink = CommandsSink(king, game)
    command = bot.decide(king, game, sink)

    # assert
    assert isinstance(command, commands.DrawSomeCards)
Ejemplo n.º 14
0
def test_rob_merchant_by_default(bot, game, thief):
    # arrange
    context = bot.create_context(thief, game)

    # act
    sink = CommandsSink(thief, game)
    command = bot.rob(sink.possible_abilities, context, thief, game)

    # assert
    assert command == commands.Rob(char=Character.Merchant)
Ejemplo n.º 15
0
def test_action_is_cash_in_if_architect(bot, game, architect):
    # arrange
    architect.cash_in(6)

    # act
    sink = CommandsSink(architect, game)
    command = bot.decide(architect, game, sink)

    # assert
    assert isinstance(command, commands.CashIn)
Ejemplo n.º 16
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), )
Ejemplo n.º 17
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
Ejemplo n.º 18
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
Ejemplo n.º 19
0
def test_kill_merchant_if_anybody_is_low_on_gold(bot, game, assassin, player1,
                                                 player2):
    # arrange
    player1.cash_in(4)

    context = bot.create_context(assassin, game)

    sink = CommandsSink(assassin, game)

    # act
    command = bot.kill(sink.possible_abilities, context, assassin, game)

    # assert
    assert command == commands.Kill(char=Character.Merchant)
Ejemplo n.º 20
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())
Ejemplo n.º 21
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
Ejemplo n.º 22
0
def test_do_tricks_swaps_hands_with_the_hoarder_low_on_cards(
        bot, game, magician, player1):
    # arrange
    for _ in range(6):
        player1.take_card(District.Docks)

    magician.take_card(District.Cathedral)

    context = bot.create_context(magician, game)

    sink = CommandsSink(magician, game)

    # act
    swap_hands = bot.do_tricks(sink.possible_abilities, context, magician,
                               game)

    # assert
    assert swap_hands == commands.SwapHands(target=player1)
Ejemplo n.º 23
0
def test_kill_architect_if_lead_player_is_low_on_cards(bot, game, assassin,
                                                       player1, player2):
    # arrange
    player1.build_district(District.Cathedral)

    player2.build_district(District.Watchtower)
    player2.build_district(District.Docks)
    player2.build_district(District.Cathedral)

    context = bot.create_context(assassin, game)

    sink = CommandsSink(assassin, game)

    # act
    command = bot.kill(sink.possible_abilities, context, assassin, game)

    # assert
    assert command == commands.Kill(char=Character.Architect)
Ejemplo n.º 24
0
def test_kill_lead_player_if_he_has_color_bias(bot, game, assassin, player1,
                                               player2):
    # arrange
    player1.build_district(District.Cathedral)

    player2.build_district(District.Watchtower)
    player2.build_district(District.Battlefield)
    player2.build_district(District.Fortress)
    player2.build_district(District.Docks)

    context = bot.create_context(assassin, game)

    sink = CommandsSink(assassin, game)

    # act
    command = bot.kill(sink.possible_abilities, context, assassin, game)

    # assert
    assert command == commands.Kill(char=Character.Warlord)
Ejemplo n.º 25
0
def test_do_tricks_replces_hand_if_nothing_to_build(bot, game, magician):
    # arrange
    magician.cash_in(1)

    magician.take_card(District.Palace)
    magician.take_card(District.TownHall)
    magician.take_card(District.Battlefield)

    context = bot.create_context(magician, game)

    sink = CommandsSink(magician, game)

    # act
    replace_hand = bot.do_tricks(sink.possible_abilities, context, magician,
                                 game)

    # assert
    assert replace_hand == commands.ReplaceHand(
        cards=[District.Palace, District.TownHall])
Ejemplo n.º 26
0
def test_income_is_taken_automatically_on_end_turn(game):
    # arrange
    player = game.add_player('Player',
                             char=Character.Warlord,
                             city=[District.Prison],
                             hand=[District.Watchtower])

    sink = CommandsSink(player, game)
    draw_cards = next(command for command in sink.possible_actions
                      if isinstance(command, commands.DrawSomeCards))
    draw_cards.select(next(iter(draw_cards.choices(player, game))))
    sink.execute(draw_cards)

    # act
    sink.end_turn()

    # assert
    assert player.gold == 1
Ejemplo n.º 27
0
def test_do_tricks_swaps_hands_with_the_leader(bot, game, magician, player1,
                                               player2):
    # arrange
    for _ in range(6):
        player1.take_card(District.Docks)

    for _ in range(5):
        player2.take_card(District.Docks)
    for _ in range(6):
        player2.build_district(District.Watchtower)

    magician.take_card(District.Cathedral)
    magician.take_card(District.Cathedral)

    context = bot.create_context(magician, game)

    sink = CommandsSink(magician, game)

    # act
    swap_hands = bot.do_tricks(sink.possible_abilities, context, magician,
                               game)

    # assert
    assert swap_hands == commands.SwapHands(target=player2)
Ejemplo n.º 28
0
def test_warlord_ability_is_final(game):
    # arrange
    hand = [District.Tavern, District.Fortress]
    city = [District.Watchtower]
    player = game.add_player('Player',
                             char=Character.Warlord,
                             hand=hand,
                             city=city)
    player.cash_in(2)

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

    destroy = sink.possible_abilities[0]
    while destroy.choices(player, game):
        destroy.select(destroy.choices(player, game)[0])
    sink.execute(destroy)

    # assert
    assert not sink.possible_builds
Ejemplo n.º 29
0
 def take_turn(self, player: Player, game: Game, sink: CommandsSink):
     command = self.decide(player, game, sink)
     if command:
         sink.execute(command)
     else:
         sink.end_turn()
Ejemplo n.º 30
0
 def take_turn(self, player: Player, game: Game, sink: CommandsSink):
     if sink.possible_actions:
         sink.execute(sink.possible_actions[0])
     else:
         sink.end_turn()