ethicalgardeners.gridworld.Cell¶
- class ethicalgardeners.gridworld.Cell(cell_type, pollution=50, pollution_increment=1)[source]¶
Bases:
objectRepresents a single cell in the grid world.
It can be of different types (
CellType). Some types can contain a flower (Flower) and an agent (Agent). It can have a pollution level that evolves over time to a speed defined bypollution_increment.- pollution_increment¶
Amount by which pollution increases each step if no flower is in the cell.
- Type:
- __init__(cell_type, pollution=50, pollution_increment=1)[source]¶
Create a new cell.
- Parameters:
cell_type (CellType) – The type of cell to create.
pollution (float, optional) – Initial pollution level of the cell. Defaults to 50 for ground cells, None for obstacles.
pollution_increment (float, optional) – Amount by which pollution increases each step if no flower is in the cell. Defaults to 1.
Methods
__init__(cell_type[, pollution, ...])Create a new cell.
Check if a flower can be planted in this cell.
Check if agents can walk on this cell.
Check if the cell is occupied by an agent.
Check if the cell contains a flower.
update_pollution(min_pollution, max_pollution)Update the pollution level of the cell based on its current state.
- can_plant_on()[source]¶
Check if a flower can be planted in this cell.
- Returns:
True if a flower can be planted in this cell, False otherwise.
- Return type:
- can_walk_on()[source]¶
Check if agents can walk on this cell.
- Returns:
True if agents can walk on this cell, False otherwise.
- Return type:
- has_agent()[source]¶
Check if the cell is occupied by an agent.
- Returns:
True if the cell is occupied by an agent, False otherwise.
- Return type:
- has_flower()[source]¶
Check if the cell contains a flower.
- Returns:
True if the cell contains a flower, False otherwise.
- Return type:
- update_pollution(min_pollution, max_pollution)[source]¶
Update the pollution level of the cell based on its current state.
For ground cells, if the cell contains a flower, its pollution decreases by the flower’s pollution reduction value, down to the minimum pollution level. If the cell does not contain a flower, its pollution increases by the pollution increment, up to the maximum pollution level.