Пример #1
0
def test_pathfind_returns_path_when_not_obstructed():
    grid = BackgroundGrid(100, 100, 20)
    grid.calculate_edges([])
    start_node = (10, 10)
    goal_node = (90, 90)
    path = grid.pathfind(start_node, goal_node)
    assert path == [(10, 10), (30, 30), (50, 50), (70, 70), (90, 90)]
Пример #2
0
def goap_boys(arena):
    walls_vector = walls_vector_from_game_objects(arena.screen_objects)
    grid = BackgroundGrid(arena.w, arena.h, 24)
    grid.calculate_edges(walls_vector)
    shopkeeper = Boy((520, 520), (10, 0), 'shopkeeper')
    shopkeeper.brain.goal_getter.intitialise_grid(grid)
    return [shopkeeper]
Пример #3
0
class CustomerManager:
    def __init__(self, arena):
        self.arena = arena
        walls_vector = walls_vector_from_game_objects(arena.screen_objects)
        self.grid = BackgroundGrid(arena.w, arena.h, 24)
        self.grid.calculate_edges(walls_vector)
        self.counter = 0

    def make_customer(self):
        customer = Boy((50, 50), (0, 0), 'customer')
        customer.brain.goal_getter.intitialise_grid(self.grid)
        self.arena.add_screen_objects([customer])

    def update(self, list_of_game_objects):
        customers = [
            obj for obj in list_of_game_objects
            if obj.image.get('role') == 'customer'
        ]
        if len(customers) < 3:
            self.counter += 1
            if self.counter >= 50:
                self.counter = 0
                if random.randint(0, 2) == 1:
                    self.make_customer()
        for customer in customers:
            state = customer.brain.action_getter.interpreter.state
            if state['at_exit'] and state['got_item']:
                customer.delete = True
Пример #4
0
def test_pathfind_returns_none_when_obstructed():
    grid = BackgroundGrid(100, 100, 20)
    wall_vector = np.array([[30, 0, 30, 100]])
    grid.calculate_edges(wall_vector)
    start_node = (10, 10)
    goal_node = (90, 90)
    path = grid.pathfind(start_node, goal_node)
    assert path is None
Пример #5
0
def test_remove_edges():
    grid = BackgroundGrid(100, 100, 20)
    wall_vector = np.array([[12, 12, 12, 32], [12, 12, 12, 14]])
    grid.calculate_edges([])
    grid.remove_edges(wall_vector)
    assert len(grid.graph.edges()) == 69
Пример #6
0
def test_edge_weights():
    grid = BackgroundGrid(100, 100, 20)
    grid.calculate_edges([])
    edge = grid.graph.get_edge_data((50, 50), (70, 70))
    assert edge['weight'] == 1.2