ethicalgardeners.agent.Agent

class ethicalgardeners.agent.Agent(position, money=0.0, seeds: dict = None)[source]

Bases: object

Represents a gardener agent in the environment.

Agents can move around the grid, plant and harvest flowers, manage seeds, and accumulate money from harvesting flowers.

position

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

Type:

tuple

money

The agent’s current monetary wealth.

Type:

float

seeds

Dictionary mapping flower types to the number of seeds the agent has.

Type:

dict

flowers_planted

Counter of flowers planted by type.

Type:

dict

flowers_harvested

Counter of flowers harvested by type.

Type:

dict

turns_without_income

Number of turns the agent has not earned money.

Type:

int

action_mask

Action mask indicating valid actions for the agent.

Type:

list

__init__(position, money=0.0, seeds: dict = None)[source]

Create a new agent.

Parameters:
  • position (tuple) – The (x, y) coordinates where the agent starts.

  • money (float, optional) – Initial amount of money the agent has. Defaults to 0.

  • seeds (dict, optional) – Dictionary mapping flower types to initial seed counts. Defaults to 10 for each type.

Methods

__init__(position[, money, seeds])

Create a new agent.

add_money(amount)

Add money to the agent's wealth.

add_seed(flower_type, num_seeds)

Add seeds of a specific flower type to the agent's inventory.

can_plant(flower_type)

Check if the agent has seeds available to plant a specific flower type.

move(new_position)

Move the agent in the specified direction.

use_seed(flower_type)

Use a seed to plant a flower of the specified type.

add_money(amount)[source]

Add money to the agent’s wealth.

Parameters:

amount (float) – The amount of money to add.

add_seed(flower_type: int, num_seeds)[source]

Add seeds of a specific flower type to the agent’s inventory.

Parameters:
  • flower_type (int) – The type of flower seeds to add.

  • num_seeds (int) – The number of seeds to add.

can_plant(flower_type: int)[source]

Check if the agent has seeds available to plant a specific flower type.

Parameters:

flower_type (int) – The type of flower to check seed availability for.

Returns:

True if the agent has at least one seed of the specified type or if seed count is -1 because this represents infinite seeds.

Return type:

bool

move(new_position)[source]

Move the agent in the specified direction.

Updates the agent’s position based on the direction action.

Parameters:

new_position (tuple) – The (x, y) coordinates of the agent in the grid.

use_seed(flower_type: int)[source]

Use a seed to plant a flower of the specified type.

Decrements the seed count for the flower type. If seed count is -1, this represents infinite seeds so the count is not decremented.

Parameters:

flower_type (int) – The type of flower to plant.

Returns:

True if the seed was successfully used, False if no seeds available.

Return type:

bool