Overview
The World
class represents a two-dimensional grid system designed for
cell-based navigation. It serves as the core data structure that your
agents will interact with, supporting key functionalities such as
movement, pathfinding, and cell manipulation.
Attributes
width
intThe width of the world. Ranging from 0 (inclusive) to the width (exclusive).
height
intThe height of the world. Ranging from 0 (inclusive) to the height (exclusive).
Methods
get_world_grid()
Returns the 2D grid representing the world.
Returns
A two-dimensional list of Cell objects representing the world's grid structure.
Example:
# world has height and width set to 3 for this example.
for row in world.get_world_grid():
for cell in row:
print(cell)
# Output:
Cell ( (0,0), Move_Cost 1)
{
}
Cell ( (0,1), Move_Cost 1)
{
}
.
.
.
Cell ( (2,2), Move_Cost 1)
{
}
get_cell_at(location: Location)
Returns the cell at the given location if it exists.
Parameters
The location of the cell.
Returns
The Cell object at the given location, or None if the location is invalid or out of bounds.
Example:
# world has height and width set to 3 for this example.
# Valid location
loc = create_location(1, 1)
print(world.get_cell_at(loc))
# Outputs:
Cell ( (1,1), Move_Cost 1)
{
# Stack Content here, if there are any layers.
}
# Invalid location
loc = create_location(4, 1)
print(world.get_cell_at(loc))
# Outputs:
None
on_map(location: Location)
Checks if a given location is on the map.
Parameters
The location to check.
Returns
True if the location is on the map, False otherwise.
Example:
# world has height and width set to 3 for this example.
# Invalid Location
is_on_map = world.on_map(create_location(3,3))
print(is_on_map)
# Output: False
# Valid Location
is_on_map = world.on_map(create_location(1, 2))
print(is_on_map)
# Output: True