Agents¶
custom_grid_env.agents.base_agent.Agent(action_space, **kwargs)
¶
Bases: Protocol
Protocol for all agents in the custom grid environment.
Any class that implements a 'get_action' method with the correct signature is considered an Agent.
Initializes the agent with the given action space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_space
|
Space
|
The action space of the environment. |
required |
**kwargs
|
Any
|
Additional keyword arguments for agent configuration. |
{}
|
Source code in src/custom_grid_env/agents/base_agent.py
get_action(observation)
¶
Returns an action based on the given observation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observation
|
dict
|
The current observation from the environment. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The action to take. |
Source code in src/custom_grid_env/agents/base_agent.py
custom_grid_env.agents.base_agent.BaseAgent(action_space, **kwargs)
¶
Base class for all agents to provide a default constructor.
Agents can inherit from this class to satisfy the Agent protocol without re-implementing the constructor.
Attributes:
| Name | Type | Description |
|---|---|---|
action_space |
Space
|
The action space of the environment. |
env |
Optional[Any]
|
Reference to the environment instance. |
perceived_agent_pos |
Optional[List[int]]
|
Agent's belief of its position. |
perceived_ghost_pos |
Optional[List[int]]
|
Agent's belief of the ghost's position. |
Initializes the agent with the given action space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_space
|
Space
|
The action space of the environment. |
required |
**kwargs
|
Any
|
Additional keyword arguments, such as 'env'. |
{}
|
Source code in src/custom_grid_env/agents/base_agent.py
custom_grid_env.agents.adversarial_agents.MinimaxAgent(action_space, depth_limit=4, **kwargs)
¶
Bases: AdversarialAgent
Agent that uses Minimax with Alpha-Beta pruning.
Source code in src/custom_grid_env/agents/adversarial_agents.py
get_action(observation)
¶
Returns the best action using minimax.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observation
|
dict
|
The current observation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The best action. |
Source code in src/custom_grid_env/agents/adversarial_agents.py
custom_grid_env.agents.adversarial_agents.ExpectimaxAgent(action_space, depth_limit=4, **kwargs)
¶
Bases: AdversarialAgent
Agent that uses Expectimax algorithm.
Source code in src/custom_grid_env/agents/adversarial_agents.py
get_action(observation)
¶
Returns the best action using expectimax.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observation
|
dict
|
The current observation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The best action. |
Source code in src/custom_grid_env/agents/adversarial_agents.py
custom_grid_env.agents.chase_ghost_agent.ChaseGhostAgent(action_space, **kwargs)
¶
Bases: BaseAgent
Ghost agent that chases the player using simple pathfinding.
This replicates the original built-in ghost behavior.
Source code in src/custom_grid_env/agents/base_agent.py
get_action(observation)
¶
Choose action to move toward the agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observation
|
dict
|
Ghost's observation with 'agent_relative_pos'. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Action (0=left, 1=down, 2=right, 3=up). |
Source code in src/custom_grid_env/agents/chase_ghost_agent.py
custom_grid_env.agents.random_ghost_agent.RandomGhostAgent(action_space, **kwargs)
¶
Bases: BaseAgent
Ghost agent that moves randomly.
Source code in src/custom_grid_env/agents/base_agent.py
get_action(observation)
¶
Returns a random action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observation
|
dict
|
The current observation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
A random action from the action space. |
Source code in src/custom_grid_env/agents/random_ghost_agent.py
custom_grid_env.agents.random_player_agent.RandomPlayerAgent(action_space, **kwargs)
¶
Bases: BaseAgent
Example random agent for demonstration.
Source code in src/custom_grid_env/agents/base_agent.py
get_action(observation)
¶
Returns a random action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observation
|
dict
|
The current observation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
A random action from the action space. |