def test_yield_resources_two_players_and_city(): board = Board() resource_freqdeck = starting_resource_bank() tile, edge1, edge2, red_node, blue_node = ( board.map.land_tiles[(0, 0, 0)], (2, 3), (3, 4), 4, 0, ) if tile.resource is None: # is desert tile, edge1, edge2, red_node, blue_node = ( board.map.land_tiles[(1, -1, 0)], (9, 2), (9, 8), 8, 6, ) # red has one settlements and one city on tile board.build_settlement(Color.RED, 2, initial_build_phase=True) board.build_road(Color.RED, edge1) board.build_road(Color.RED, edge2) board.build_settlement(Color.RED, red_node) board.build_city(Color.RED, red_node) # blue has a city in tile board.build_settlement(Color.BLUE, blue_node, initial_build_phase=True) board.build_city(Color.BLUE, blue_node) payout, depleted = yield_resources(board, resource_freqdeck, tile.number) assert len(depleted) == 0 assert freqdeck_count(payout[Color.RED], tile.resource) >= 3 # type: ignore assert freqdeck_count(payout[Color.BLUE], tile.resource) >= 2 # type: ignore
def test_can_add(): a = [0, 0, 0, 0, 0] b = [0, 0, 0, 0, 0] freqdeck_replenish(a, 10, ORE) freqdeck_replenish(b, 1, ORE) assert freqdeck_count(a, ORE) == 10 assert freqdeck_count(b, ORE) == 1 b = freqdeck_add(b, a) assert freqdeck_count(a, ORE) == 10 assert freqdeck_count(b, ORE) == 11
def test_can_subtract(): a = [0, 0, 0, 0, 0] b = [0, 0, 0, 0, 0] freqdeck_replenish(a, 13, SHEEP) freqdeck_replenish(b, 4, SHEEP) assert freqdeck_count(a, SHEEP) == 13 assert freqdeck_count(b, SHEEP) == 4 freqdeck_replenish(b, 11, SHEEP) # now has 15 b = freqdeck_subtract(b, a) assert freqdeck_count(a, SHEEP) == 13 assert freqdeck_count(b, SHEEP) == 2
def maritime_trade_possibilities(state, color) -> List[Action]: trade_offers = set() # Get lowest rate per resource port_resources = set(state.board.get_player_port_resources(color)) rates: Dict[FastResource, int] = { WOOD: 4, BRICK: 4, SHEEP: 4, WHEAT: 4, ORE: 4 } if None in port_resources: rates = {WOOD: 3, BRICK: 3, SHEEP: 3, WHEAT: 3, ORE: 3} for resource in port_resources: if resource != None: rates[resource] = 2 # For resource in hand for resource in RESOURCES: amount = player_num_resource_cards(state, color, resource) if amount >= rates[resource]: resource_out: List[Any] = [resource] * rates[resource] resource_out += [None] * (4 - rates[resource]) for j_resource in RESOURCES: if (resource != j_resource and freqdeck_count( state.resource_freqdeck, j_resource) > 0): trade_offer = tuple(resource_out + [j_resource]) trade_offers.add(trade_offer) return list( map(lambda t: Action(color, ActionType.MARITIME_TRADE, t), trade_offers))
def test_resource_freqdeck_integration(): deck = starting_resource_bank() assert freqdeck_count(deck, WHEAT) == 19 assert sum(deck) == 19 * 5 assert freqdeck_can_draw(deck, 10, WHEAT) freqdeck_draw(deck, 10, WHEAT) assert freqdeck_count(deck, WHEAT) == 9 freqdeck_draw(deck, 9, WHEAT) assert freqdeck_count(deck, WHEAT) == 0 freqdeck_replenish(deck, 2, WHEAT) assert freqdeck_count(deck, WHEAT) == 2 freqdeck_draw(deck, 1, WHEAT) assert freqdeck_count(deck, WHEAT) == 1
def game_features(game: Game, p0_color: Color): # BANK_WOODS, BANK_WHEATS, ..., BANK_DEV_CARDS possibilities = set([a.action_type for a in game.state.playable_actions]) features = { "BANK_DEV_CARDS": len(game.state.development_listdeck), "IS_MOVING_ROBBER": ActionType.MOVE_ROBBER in possibilities, "IS_DISCARDING": ActionType.DISCARD in possibilities, } for resource in RESOURCES: features[f"BANK_{resource}"] = freqdeck_count( game.state.resource_freqdeck, resource) return features
def test_yield_resources(): board = Board() resource_freqdeck = starting_resource_bank() tile = board.map.land_tiles[(0, 0, 0)] if tile.resource is None: # is desert tile = board.map.land_tiles[(-1, 0, 1)] board.build_settlement(Color.RED, 3, initial_build_phase=True) payout, depleted = yield_resources(board, resource_freqdeck, tile.number) assert len(depleted) == 0 assert freqdeck_count(payout[Color.RED], tile.resource) >= 1 # type: ignore
def test_play_year_of_plenty_gives_player_resources(): players = [SimplePlayer(Color.RED), SimplePlayer(Color.BLUE)] state = State(players) player_to_act = players[0] player_deck_replenish(state, player_to_act.color, YEAR_OF_PLENTY, 1) action_to_execute = Action(player_to_act.color, ActionType.PLAY_YEAR_OF_PLENTY, [ORE, WHEAT]) apply_action(state, action_to_execute) for card_type in RESOURCES: if card_type == ORE or card_type == WHEAT: assert player_num_resource_cards(state, player_to_act.color, card_type) == 1 assert freqdeck_count(state.resource_freqdeck, card_type) == 18 else: assert player_num_resource_cards(state, player_to_act.color, card_type) == 0 assert freqdeck_count(state.resource_freqdeck, card_type) == 19 assert get_dev_cards_in_hand(state, player_to_act.color, YEAR_OF_PLENTY) == 0
def test_yield_resources_two_settlements(): board = Board() resource_freqdeck = starting_resource_bank() tile, edge2, node2 = board.map.land_tiles[(0, 0, 0)], (4, 5), 5 if tile.resource is None: # is desert tile, edge2, node2 = board.map.land_tiles[(-1, 0, 1)], (4, 15), 15 board.build_settlement(Color.RED, 3, initial_build_phase=True) board.build_road(Color.RED, (3, 4)) board.build_road(Color.RED, edge2) board.build_settlement(Color.RED, node2) payout, depleted = yield_resources(board, resource_freqdeck, tile.number) assert len(depleted) == 0 assert freqdeck_count(payout[Color.RED], tile.resource) >= 2 # type: ignore
def test_empty_payout_if_not_enough_resources(): board = Board() resource_freqdeck = starting_resource_bank() tile = board.map.land_tiles[(0, 0, 0)] if tile.resource is None: # is desert tile = board.map.land_tiles[(-1, 0, 1)] board.build_settlement(Color.RED, 3, initial_build_phase=True) board.build_city(Color.RED, 3) freqdeck_draw(resource_freqdeck, 18, tile.resource) # type: ignore payout, depleted = yield_resources(board, resource_freqdeck, tile.number) assert depleted == [tile.resource] assert ( Color.RED not in payout or freqdeck_count(payout[Color.RED], tile.resource) == 0 # type: ignore )
def test_from_array(): a = freqdeck_from_listdeck([BRICK, BRICK, WOOD]) assert sum(a) == 3 assert freqdeck_count(a, BRICK) == 2 assert freqdeck_count(a, WOOD) == 1