示例#1
0
def test_robber_possibilities():
    red = SimplePlayer(Color.RED)
    blue = SimplePlayer(Color.BLUE)
    orange = SimplePlayer(Color.ORANGE)
    players = [red, blue, orange]
    state = State(players)

    # one for each resource tile (excluding desert)
    assert len(robber_possibilities(state, Color.RED)) == 18

    # assert same number of possibilities, b.c. players have no cards.
    state.board.build_settlement(Color.BLUE, 3, initial_build_phase=True)
    state.board.build_settlement(Color.ORANGE, 0, initial_build_phase=True)
    assert len(robber_possibilities(state, Color.RED)) == 18

    # assert same number of possibilities, b.c. only one player to rob in this tile
    player_deck_replenish(state, orange.color, WHEAT)
    assert len(robber_possibilities(state, Color.RED)) == 18

    # now possibilites increase by 1 b.c. we have to decide to steal from blue or orange
    # Unless desert is (0,0,0)... in which case still at 18...
    player_deck_replenish(state, blue.color, WHEAT)
    possibilities = len(robber_possibilities(state, Color.RED))
    assert possibilities == 19 or (
        possibilities == 18
        and state.board.map.land_tiles[(0, 0, 0)].resource is None)
示例#2
0
def test_playable_cards():
    player = SimplePlayer(Color.RED)

    state = State([player])
    player_deck_replenish(state, Color.RED, "KNIGHT")
    player_clean_turn(state, Color.RED)

    assert player_can_play_dev(state, Color.RED, "KNIGHT")
示例#3
0
def test_building_city_gives_vp():
    players = [SimplePlayer(Color.RED), SimplePlayer(Color.BLUE)]
    state = State(players)

    build_settlement(state, state.colors[0], 0, True)
    player_deck_replenish(state, state.colors[0], WHEAT, 2)
    player_deck_replenish(state, state.colors[0], ORE, 2)
    build_city(state, state.colors[0], 0)
    assert state.player_state["P0_VICTORY_POINTS"] == 2
    assert state.player_state["P0_ACTUAL_VICTORY_POINTS"] == 2
示例#4
0
def test_can_trade_with_port():
    players = [SimplePlayer(Color.RED)]

    state = State(players)
    state.board.build_settlement(Color.RED, 26, initial_build_phase=True)

    port_tile = state.board.map.tiles[(3, -3, 0)]  # port with node_id=25,26
    resource_out = port_tile.resource or WHEAT  # type: ignore
    num_out = 3 if port_tile.resource is None else 2  # type: ignore
    player_deck_replenish(state, Color.RED, resource_out, num_out)

    possibilities = maritime_trade_possibilities(state, Color.RED)
    assert len(possibilities) == 4
示例#5
0
def test_4to1_maritime_trade_possibilities():
    player = SimplePlayer(Color.RED)
    state = State([player])

    possibilities = maritime_trade_possibilities(state, player.color)
    assert len(possibilities) == 0

    player_deck_replenish(state, player.color, WHEAT, 4)
    possibilities = maritime_trade_possibilities(state, player.color)
    print(possibilities)
    assert len(possibilities) == 4

    player_deck_replenish(state, player.color, BRICK, 4)
    possibilities = maritime_trade_possibilities(state, player.color)
    assert len(possibilities) == 8
示例#6
0
def test_play_year_of_plenty_not_enough_resources():
    players = [SimplePlayer(Color.RED), SimplePlayer(Color.BLUE)]
    player_to_act = players[0]
    game = Game(players)
    game.state.resource_freqdeck = [0, 0, 0, 0, 0]
    player_deck_replenish(game.state, player_to_act.color, YEAR_OF_PLENTY)

    action_to_execute = Action(
        player_to_act.color,
        ActionType.PLAY_YEAR_OF_PLENTY,
        [ORE, WHEAT],
    )

    with pytest.raises(ValueError):  # not enough cards in bank
        game.execute(action_to_execute)
示例#7
0
def test_road_possible_actions():
    player = SimplePlayer(Color.RED)
    state = State([player])

    assert len(road_building_possibilities(
        state, Color.RED)) == 0  # no money or place

    state.board.build_settlement(Color.RED, 3, initial_build_phase=True)
    assert len(road_building_possibilities(state, Color.RED)) == 0  # no money

    player_deck_replenish(state, player.color, WOOD)
    player_deck_replenish(state, player.color, BRICK)
    assert len(road_building_possibilities(state, Color.RED)) == 3

    state.board.build_settlement(Color.RED, 1, initial_build_phase=True)
    assert len(road_building_possibilities(state, Color.RED)) == 6
示例#8
0
def test_city_playable_actions():
    player = SimplePlayer(Color.RED)
    state = State([player])

    assert len(city_possibilities(state, Color.RED)) == 0  # no money or place

    state.board.build_settlement(Color.RED, 3, initial_build_phase=True)
    build_settlement(state, player.color, 3, True)
    assert len(city_possibilities(state, Color.RED)) == 0  # no money

    player_deck_replenish(state, Color.RED, WHEAT, 2)
    player_deck_replenish(state, Color.RED, ORE, 3)
    assert len(city_possibilities(state, Color.RED)) == 1

    state.board.build_settlement(Color.RED, 0, initial_build_phase=True)
    build_settlement(state, player.color, 0, True)
    assert len(city_possibilities(state, Color.RED)) == 2
示例#9
0
def test_discard_config(fake_roll_dice):
    fake_roll_dice.return_value = (1, 6)
    players = [SimplePlayer(Color.RED), SimplePlayer(Color.BLUE)]
    game = Game(players, discard_limit=10)
    while not any(
        a.action_type == ActionType.ROLL for a in game.state.playable_actions
    ):
        game.play_tick()

    until_nine = 9 - player_num_resource_cards(game.state, players[1].color)
    player_deck_replenish(game.state, players[1].color, WHEAT, until_nine)
    assert player_num_resource_cards(game.state, players[1].color) == 9
    game.play_tick()  # should be p0 rolling.

    assert game.state.playable_actions != [
        Action(players[1].color, ActionType.DISCARD, None)
    ]
示例#10
0
def test_seven_cards_dont_trigger_discarding(fake_roll_dice):
    fake_roll_dice.return_value = (1, 6)
    players = [SimplePlayer(Color.RED), SimplePlayer(Color.BLUE)]

    # Play initial build phase
    game = Game(players)
    while not any(
        a.action_type == ActionType.ROLL for a in game.state.playable_actions
    ):
        game.play_tick()

    until_seven = 7 - player_num_resource_cards(game.state, players[1].color)
    player_deck_replenish(game.state, players[1].color, WHEAT, until_seven)
    assert player_num_resource_cards(game.state, players[1].color) == 7
    game.play_tick()  # should be player 0 rolling.

    assert not any(
        a.action_type == ActionType.DISCARD for a in game.state.playable_actions
    )
示例#11
0
def test_maritime_possibities_respect_bank_not_having_cards():
    player = SimplePlayer(Color.RED)
    state = State([player])
    player_deck_replenish(state, player.color, WHEAT)
    assert len(maritime_trade_possibilities(state, player.color)) == 0