ethicalgardeners.gridworld.Cell

class ethicalgardeners.gridworld.Cell(cell_type, pollution=50, pollution_increment=1)[source]

Bases: object

Represents 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 by pollution_increment.

cell_type

Type of the cell (ground, obstacle).

Type:

CellType

flower

The flower present in this cell, if any.

Type:

Flower

agent

The agent currently occupying this cell, if any.

Type:

Agent

pollution

Current pollution level of the cell, if applicable.

Type:

float

pollution_increment

Amount by which pollution increases each step if no flower is in the cell.

Type:

float

__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.

can_plant_on()

Check if a flower can be planted in this cell.

can_walk_on()

Check if agents can walk on this cell.

has_agent()

Check if the cell is occupied by an agent.

has_flower()

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:

bool

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:

bool

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:

bool

has_flower()[source]

Check if the cell contains a flower.

Returns:

True if the cell contains a flower, False otherwise.

Return type:

bool

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.

Parameters:
  • min_pollution (float) – Minimum pollution level allowed.

  • max_pollution (float) – Maximum pollution level allowed.