def test_can_build_second_settlement(self): player = Player() other_player = Player() state = State(players=[player, other_player]) state.board.vertices[-1].assign_building(building=Settlement( player=other_player)) assert len(state.can_build_second_settlement(player=player)) == 51 assert state.can_build_second_settlement(player=player)[0] == Action( name="build_second_settlement", kwargs={"vertex": state.board.vertices[0]})
def test_can_place_building_returns_false_if_no_roads_exist(self): player = Player() different_player = Player() vertex = Vertex(id=0) edge_no_road = Edge(id=0) edge_road_different_player = Edge(id=1) vertex.edges = [edge_no_road, edge_road_different_player] edge_no_road.vertices = [vertex] edge_road_different_player.vertices = [vertex] edge_road_different_player.road = Road(player=different_player) assert not vertex.can_place_building(player=player)
def test_remove_raises_if_count_less_than_1(self): player = Player() player_hand = PlayerHand(player=player) with pytest.raises( RuntimeError, match="Cannot remove 0 or less cards from the hand." ): player_hand.remove(resource_type=Clay, count=0)
def test_remove_has_at_least_x_of_resource_type(self): player = Player() player_hand = PlayerHand(player=player) player_hand.hand[Clay] = 2 removed_count = player_hand.remove(resource_type=Clay, count=1) assert removed_count == 1 assert player_hand.hand[Clay] == 1
def test_remove_has_less_than_x_of_resource_type(self): player = Player() player_hand = PlayerHand(player=player) player_hand.hand[Clay] = 2 removed_count = player_hand.remove(resource_type=Clay, count=3) assert removed_count == 2 assert player_hand.hand[Clay] == 0
def test_add_raises_if_count_less_than_1(self): player = Player() player_hand = PlayerHand(player=player) with pytest.raises( RuntimeError, match="Cannot add 0 or less cards to the hand." ): player_hand.add(resource_type=Clay, count=0)
def test_assign_road(self): player = Player() edge = Edge(id=0) assert not edge.road road = Road(player=player) edge.assign_road(road=road) assert edge.road == road
def test_init_hand(self): player = Player() player_hand = PlayerHand(player=player) assert player_hand.hand[Clay] == 0 assert player_hand.hand[Rock] == 0 assert player_hand.hand[Sheep] == 0 assert player_hand.hand[Wheat] == 0 assert player_hand.hand[Wood] == 0
def test_can_build_settlement_returns_nothing_if_no_vertices_available( self): player = Player() state = State(players=[player]) for vertex in state.board.vertices: vertex.building = Settlement(player=player) assert state.can_build_settlement(player=player) == []
def test_can_buy_road(self): player = Player() player_hand = PlayerHand(player=player) assert not player_hand.can_buy_road() player_hand.hand[Clay] = 1 player_hand.hand[Wood] = 1 assert player_hand.can_buy_road()
def test_build_starating_road(self): player = Player() state = State(players=[player]) assert not state.board.edges[0].road state.build_starting_road(player=player, edge=state.board.edges[0]) assert state.board.edges[0].road assert state.board.edges[0].road.player == player
def test_can_buy_city(self): player = Player() player_hand = PlayerHand(player=player) assert not player_hand.can_buy_city() player_hand.hand[Rock] = 3 player_hand.hand[Wheat] = 2 assert player_hand.can_buy_city()
def test_can_place_building_returns_false_if_building_exists(self): player = Player() vertex = Vertex(id=0) edge = Edge(id=0) edge.vertices = [vertex] edge.road = Road(player) vertex.edges = [edge] vertex.assign_building(building=Settlement(player=player)) assert not vertex.can_place_building(player=player)
def test_build_city_resources_removed(self): player = Player() state = State(players=[player]) state.player_hand[player].add(resource_type=Rock, count=3) state.player_hand[player].add(resource_type=Wheat, count=2) state.build_city(player=player, vertex=state.board.vertices[0]) assert not state.player_hand[player].has(resource_type=Rock, count=1) assert not state.player_hand[player].has(resource_type=Wheat, count=1)
def test_build_road_exists(self): player = Player() state = State(players=[player]) state.player_hand[player].add(resource_type=Wood, count=1) state.player_hand[player].add(resource_type=Clay, count=1) state.build_road(player=player, edge=state.board.edges[0]) assert state.board.edges[0].road assert state.board.edges[0].road.player == player
def test_build_road_cards_removed(self): player = Player() state = State(players=[player]) state.player_hand[player].add(resource_type=Wood, count=1) state.player_hand[player].add(resource_type=Clay, count=1) state.build_road(player=player, edge=state.board.edges[0]) assert not state.player_hand[player].has(resource_type=Wood, count=1) assert not state.player_hand[player].has(resource_type=Clay, count=1)
def test_can_buy_development_card(self): player = Player() player_hand = PlayerHand(player=player) assert not player_hand.can_buy_development_card() player_hand.hand[Rock] = 1 player_hand.hand[Sheep] = 1 player_hand.hand[Wheat] = 1 assert player_hand.can_buy_development_card()
def test_can_place_road_retruns_true_if_adjacent_building_for_player(self): player = Player() edge = Edge(id=0) vertex = Vertex(id=0) edge.vertices = [vertex] vertex.edges = [edge] vertex.assign_building(building=Settlement(player=player)) assert edge.can_place_road(player=player)
def test_build_city_exists(self): player = Player() state = State(players=[player]) state.player_hand[player].add(resource_type=Rock, count=3) state.player_hand[player].add(resource_type=Wheat, count=2) state.build_city(player=player, vertex=state.board.vertices[0]) assert state.board.vertices[0].building assert isinstance(state.board.vertices[0].building, City) assert state.board.vertices[0].building.player == player
def test_build_second_settlement_building_exists(self): player = Player() state = State(players=[player]) assert not state.board.vertices[0].building state.build_second_settlement(player=player, vertex=state.board.vertices[0]) assert state.board.vertices[0].building assert isinstance(state.board.vertices[0].building, Settlement) assert state.board.vertices[0].building.player == player
def test_build_second_settlement_starting_resources_added_to_hand(self): player = Player() state = State(players=[player]) hex = state.board.hexes[0] hex.resource_type = Rock assert state.player_hand[player].has(resource_type=Rock, count=0) state.build_second_settlement(player=player, vertex=state.board.vertices[0]) assert state.player_hand[player].has(resource_type=Rock, count=1)
def test_can_place_road_returns_false_if_no_adjacent_roads_for_player( self, ): player1 = Player() player2 = Player() edge = Edge(id=0) edge_no_road = Edge(id=1) edge_with_road_player2 = Edge(id=2) edge_with_road_player2.road = Road(player=player2) v1 = Vertex(id=0) v2 = Vertex(id=1) # Connect vertex to edges edge.vertices = [v1, v2] edge_no_road.vertices = [v1] edge_with_road_player2.vertices = [v2] v1.edges = [edge, edge_no_road] v2.edges = [edge, edge_with_road_player2] assert not edge.can_place_road(player=player1)
def test_can_place_building_returns_true(self): player = Player() vertex = Vertex(id=0) edge = Edge(id=0) neighbour_vertex = Vertex(id=1) edge.road = Road(player) vertex.edges = [edge] neighbour_vertex.edges = [edge] edge.vertices = [vertex, neighbour_vertex] assert vertex.can_place_building(player=player)
def test_can_buy_settlement(self): player = Player() player_hand = PlayerHand(player=player) assert not player_hand.can_buy_settlement() player_hand.hand[Wood] = 1 player_hand.hand[Clay] = 1 player_hand.hand[Wheat] = 1 player_hand.hand[Sheep] = 1 assert player_hand.can_buy_settlement()
def test_can_place_building_Returns_false_if_building_is_nearby(self): player = Player() vertex = Vertex(id=0) neighbour_vertex = Vertex(id=1) edge = Edge(id=0) vertex.edges = [edge] neighbour_vertex.edges = [edge] neighbour_vertex.building = Settlement(player=player) edge.vertices = [vertex, neighbour_vertex] edge.road = Road(player=player) assert not vertex.can_place_building(player=player)
def test_can_build_road_returns_possible_build_locations(self): player = Player() state = State(players=[player]) state.player_hand[player].add(Wood, 1) state.player_hand[player].add(Clay, 1) state.board.edges[0].road = Road(player=player) assert state.can_build_road(player=player) == [ Action(name="build_road", kwargs={"edge": state.board.edges[1]}), Action(name="build_road", kwargs={"edge": state.board.edges[6]}), ]
def test_can_build_starting_road(self): player = Player() state = State(players=[player]) state.board.vertices[0].assign_building(building=Settlement( player=player)) assert state.can_build_starting_road(player=player) == [ Action(name="build_starting_road", kwargs={"edge": state.board.edges[0]}), Action(name="build_starting_road", kwargs={"edge": state.board.edges[6]}), ]
def test_build_settlement_exists(self): player = Player() state = State(players=[player]) state.player_hand[player].add(resource_type=Wood, count=1) state.player_hand[player].add(resource_type=Clay, count=1) state.player_hand[player].add(resource_type=Wheat, count=1) state.player_hand[player].add(resource_type=Sheep, count=1) state.build_settlement(player=player, vertex=state.board.vertices[0]) assert state.board.vertices[0].building assert isinstance(state.board.vertices[0].building, Settlement) assert state.board.vertices[0].building.player == player
def test_build_settlement_resources_removed(self): player = Player() state = State(players=[player]) state.player_hand[player].add(resource_type=Wood, count=1) state.player_hand[player].add(resource_type=Clay, count=1) state.player_hand[player].add(resource_type=Wheat, count=1) state.player_hand[player].add(resource_type=Sheep, count=1) state.build_settlement(player=player, vertex=state.board.vertices[0]) assert not state.player_hand[player].has(resource_type=Wood, count=1) assert not state.player_hand[player].has(resource_type=Clay, count=1) assert not state.player_hand[player].has(resource_type=Wheat, count=1) assert not state.player_hand[player].has(resource_type=Sheep, count=1)
def test_can_place_road_returns_true_if_adjacent_road_for_player(self): player = Player() edge = Edge(id=0) edge_with_road = Edge(id=1) edge_with_road.road = Road(player=player) vertex = Vertex(id=0) # Connect vertex to edges edge.vertices = [vertex] edge_with_road.vertices = [vertex] vertex.edges = [edge, edge_with_road] assert edge.can_place_road(player=player)