ethicalgardeners.renderer.ConsoleRenderer

class ethicalgardeners.renderer.ConsoleRenderer(characters=None, display=False)[source]

Bases: Renderer

Text-based implementation of the Renderer interface.

This renderer displays the simulation environment as ASCII characters in the console. It provides a lightweight, platform-independent visualization solution that works in terminal environments.

The renderer uses a configurable set of characters to represent different elements of the environment (agents, flowers, empty cells, etc.).

characters

Mapping of environment elements to their ASCII character representations. The default mapping includes:

  • ‘ground’: ‘ ‘ (space) - Empty ground cell

  • ‘obstacle’: ‘#’ - Cell with an obstacle

  • ‘flower’: ‘F’ - Cell with a flower

  • ‘agent’: ‘A’ - Cell with an agent

Type:

dict

display

Inherited from Renderer. Flag to enable rendering. If True, the renderer will display the environment in the console.

Type:

bool

grid_representation

List of strings representing the grid world, where each string corresponds to a row in the grid.

Type:

list

_grid_world

The grid world environment to render.

Type:

GridWorld

_agents

Dictionary mapping the agent’s gymnasium ID to the Agent instance.

Type:

dict

__init__(characters=None, display=False)[source]

Create the console renderer.

Parameters:
  • characters (dict, optional) – Mapping of environment elements to their ASCII character representations. Defaults to a basic set with ‘ ‘ for empty cells, ‘#’ for obstacles, ‘F’ for flowers, and ‘A’ for agents.

  • display (bool, optional) – Flag to enable rendering. If True, the renderer will display the environment in the console.

Methods

__init__([characters, display])

Create the console renderer.

display_render()

Display the rendered frame in the console.

end_render()

Finalize the rendering process.

init(grid_world)

Initialize the renderer with the grid world environment.

render(grid_world, agents)

Render the current state of the grid world as text.

display_render()[source]

Display the rendered frame in the console.

This method prints the grid representation to the console, showing the current state of the environment with all elements represented by their respective characters.

end_render()

Finalize the rendering process.

This method is called at the end of simulation to perform cleanup tasks and finalize any outputs.

init(grid_world)

Initialize the renderer with the grid world environment.

This method is called once at the beginning of simulation to set up the rendering environment based on the grid world properties.

Parameters:

grid_world (GridWorld) – The grid world environment to be rendered.

render(grid_world, agents: dict)[source]

Render the current state of the grid world as text.

This method create a text representation of the grid world, using the character mappings to display different elements. Each cell is represented by a single character followed by numbers for plants and agents, with rows separated by newlines.

Parameters:
  • grid_world (GridWorld) – The current state of the world grid to render.

  • agents (dict) – Dictionary mapping the agent’s gymnasium ID to the Agent instance of the agents to display.