logic package

Submodules

logic.behavior module

logic.behavior.distance(a, b)[source]

Calculate Manhattan distance between two animals.

Parameters: a (Animal): First animal object with x and y coordinates. b (Animal): Second animal object with x and y coordinates.

Returns: int: Manhattan distance between a and b.

logic.behavior.random_move(animal, grid_size, terrain=None)[source]

Move the animal to a random adjacent cell based on its speed.

Parameters: animal (Animal): The animal object to move. grid_size (int): The size of the simulation grid. terrain (Terrain, optional): Terrain object for checking movement constraints.

logic.behavior.chase(animal, others, foodweb, radius=3, terrain=None)[source]

Chase the nearest prey within a radius if the animal has low energy.

Parameters: animal (Animal): The predator trying to chase. others (list): List of other Animal objects in the grid. foodweb (FoodWeb): Object representing predator-prey relationships. radius (int, optional): Distance within which prey can be chased. Defaults to 3. terrain (Terrain, optional): Terrain object to validate movement.

logic.behavior.flee(animal, others, foodweb, terrain=None)[source]

Move the animal away from nearby predators.

Parameters: animal (Animal): The animal attempting to flee. others (list): List of other Animal objects in the grid. foodweb (FoodWeb): Object representing predator-prey relationships. terrain (Terrain, optional): Terrain object to validate movement.

logic.behavior.eat_if_possible(predator, others, foodweb)[source]

Make the predator eat a prey at the same location if possible.

Parameters: predator (Animal): The predator animal. others (list): List of other Animal objects. foodweb (FoodWeb): Object representing predator-prey relationships.

logic.reproduction module

logic.reproduction.reproduce(organisms, grid_size, step_counter)[source]

Handles the reproduction logic for organisms in the simulation.

This function spawns new Producer or Consumer organisms under various conditions such as energy thresholds, trophic level, proximity, and availability of prey.

Parameters: organisms (list): List of organism objects (Producers or Consumers). grid_size (int): Size of the simulation grid. step_counter (int): Current simulation step used for cooldown and timing logic.

Returns: list: List of newly spawned organism objects.

Module contents