def test_set_vertices(self): edge = Edge(id=0) vertex = Vertex(id=0) edge.vertices = [vertex] assert edge.vertices == [vertex]
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_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 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_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 __init__(self): # Randomly select resource type and number for each hex. self.hexes = self.setup_hexes() self.vertices = [Vertex(id=i) for i in range(54)] self.edges = [Edge(id=i) for i in range(72)] for hex_index, vertex_indices in enumerate(hex_to_vertex): hex = self.hexes[hex_index] for vertex_index in vertex_indices: vertex = self.vertices[vertex_index] hex.vertices.append(vertex) vertex.hexes.append(hex) for edge_index, vertex_indices in enumerate(edge_to_vertices): edge = self.edges[edge_index] for vertex_index in vertex_indices: vertex = self.vertices[vertex_index] vertex.edges.append(edge) edge.vertices.append(vertex)
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)
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 build_road(self, player: Player, edge: Edge): self.player_hand[player].remove(resource_type=Wood, count=1) self.player_hand[player].remove(resource_type=Clay, count=1) new_road = Road(player=player) edge.assign_road(road=new_road)
def build_starting_road(self, player: Player, edge: Edge): new_road = Road(player=player) edge.assign_road(road=new_road)
def test_init_no_vertices(self): edge = Edge(id=0) assert edge.id == 0 assert edge.vertices == []
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_road_returns_false_if_road_already_exists(self): edge = Edge(id=0) player = Player() edge.road = Road(player=player) assert not edge.can_place_road(player=player)
def test_repr(self): assert Edge(id=0).__repr__() == "edge-0"