Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    def test_set_vertices(self):
        edge = Edge(id=0)
        vertex = Vertex(id=0)

        edge.vertices = [vertex]

        assert edge.vertices == [vertex]
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    def test_init(self):
        port = RockPort()
        vertex = Vertex(id=0, port=port)

        assert vertex.id == 0
        assert vertex.edges == []
        assert vertex.hexes == []
        assert vertex.port == port
        assert not vertex.building
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    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)
Exemplo n.º 11
0
    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)
Exemplo n.º 12
0
    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)
Exemplo n.º 13
0
 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)
Exemplo n.º 14
0
 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())
Exemplo n.º 15
0
 def test_assign_building_successfully(self):
     vertex = Vertex(id=0)
     building = Building()
     vertex.assign_building(building=building)
     assert vertex.building == building
Exemplo n.º 16
0
 def build_first_settlement(self, player: Player, vertex: Vertex):
     new_settlement = Settlement(player=player)
     vertex.assign_building(new_settlement)
Exemplo n.º 17
0
 def test_repr(self):
     assert Vertex(id=0).__repr__() == "vertex-0"