ethicalgardeners.gridworld.Flower

class ethicalgardeners.gridworld.Flower(position, flower_type, flowers_data: dict, growth_stage=0)[source]

Bases: object

Represents a flower that can be planted and harvested in the environment.

Flowers grow through several stages and reduce pollution in their cell. Different flower types have different growth patterns, prices, and pollution reduction capabilities.

position

The (x, y) coordinates of the flower in the grid.

Type:

tuple

flower_type

The type of flower, determining its growth and pollution reduction.

Type:

int

price

The monetary value of the flower when harvested.

Type:

float

pollution_reduction

List of pollution reduction values for each growth stage.

Type:

list

num_growth_stage

Total number of growth stages for this flower.

Type:

int

current_growth_stage

Current growth stage of the flower, starting at 0.

Type:

int

__init__(position, flower_type, flowers_data: dict, growth_stage=0)[source]

Create a new flower.

Parameters:
  • position (tuple) – The (x, y) coordinates where the flower is planted.

  • flower_type (int) – The type of flower to create.

  • flowers_data (dict) – Configuration data for flower types; a dictionary mapping flower type IDs to a dictionary of properties, containing keys and pollution_reduction.

  • growth_stage (int, optional) – The number of growth stages for this flower. Defaults to 0 (the initial stage).

Methods

__init__(position, flower_type, flowers_data)

Create a new flower.

get_pollution_reduction()

Return the current pollution reduction provided by the flower.

grow()

Advance the flower to the next growth stage if not fully grown.

is_grown()

Check if the flower has reached its final growth stage.

get_pollution_reduction()[source]

Return the current pollution reduction provided by the flower.

The pollution reduction depends on the current growth stage and the flower type.

Returns:

The amount of pollution reduced by this flower at its current stage.

Return type:

float

grow()[source]

Advance the flower to the next growth stage if not fully grown.

By default, the flower grows 1 stage at each time step, up to the maximum stage defined for this flower type.

is_grown()[source]

Check if the flower has reached its final growth stage.

Returns:

True if the flower is fully grown, False otherwise.

Return type:

bool