def build_second_settlement(self, player: Player, vertex: Vertex): new_settlement = Settlement(player=player) vertex.assign_building(new_settlement) for hex in self.board.hexes: if vertex in hex.vertices and hex.resource_type: self.player_hand[player].add(resource_type=hex.resource_type, count=1)
def build_settlement(self, player: Player, vertex: Vertex): self.player_hand[player].remove(resource_type=Wood, count=1) self.player_hand[player].remove(resource_type=Clay, count=1) self.player_hand[player].remove(resource_type=Wheat, count=1) self.player_hand[player].remove(resource_type=Sheep, count=1) new_settlement = Settlement(player=player) vertex.assign_building(building=new_settlement)
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_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 build_city(self, player: Player, vertex: Vertex): self.player_hand[player].remove(resource_type=Rock, count=3) self.player_hand[player].remove(resource_type=Wheat, count=2) new_city = City(player=player) vertex.assign_building(building=new_city)
def build_first_settlement(self, player: Player, vertex: Vertex): new_settlement = Settlement(player=player) vertex.assign_building(new_settlement)
def test_assign_building_successfully(self): vertex = Vertex(id=0) building = Building() vertex.assign_building(building=building) assert vertex.building == building
def test_assign_building_raises_error_if_already_assigned(self): vertex = Vertex(id=0) vertex.building = Building() with pytest.raises(RuntimeError, match=r"A building already exists at this vertex"): vertex.assign_building(building=Building())