POMDPPlanners.environments.pacman_pomdp package
PacMan POMDP package with sprite-based visualization.
- class POMDPPlanners.environments.pacman_pomdp.PacManPOMDP(maze_size=(7, 7), walls=None, initial_pellets=None, initial_pacman_pos=(0, 0), num_ghosts=1, initial_ghost_positions=None, initial_ghost_pos=None, pellet_reward=10.0, ghost_collision_penalty=-100.0, step_penalty=-1.0, win_reward=100.0, ghost_aggressiveness=2.0, ghost_coordination='independent', ghost_strategies=None, observation_noise_factor=0.3, max_observation_noise=1.5, dangerous_areas=None, dangerous_area_radius=1.0, dangerous_area_penalty=5.0, discount_factor=0.95, name='PacManPOMDP', output_dir=None, debug=False, reward_model_type=RewardModelType.CONSTANT_HAZARD_PENALTY, penalty_decay=1.0)[source]
Bases:
DiscreteActionsEnvironmentPacMan POMDP environment inspired by the classic arcade game.
This environment implements a simplified PacMan game where PacMan must collect pellets while avoiding a single ghost. The ghost position is only partially observable through noisy sensor readings.
- Parameters:
num_ghosts (int)
pellet_reward (float)
ghost_collision_penalty (float)
step_penalty (float)
win_reward (float)
ghost_aggressiveness (float)
ghost_coordination (str)
observation_noise_factor (float)
max_observation_noise (float)
dangerous_area_radius (float)
dangerous_area_penalty (float)
discount_factor (float)
name (str)
output_dir (Path | None)
debug (bool)
reward_model_type (RewardModelType)
penalty_decay (float)
- maze_size
Grid dimensions as (rows, cols)
- walls
Set of wall positions as (row, col) tuples
- initial_pellets
List of initial pellet positions
- pellet_reward
Reward for collecting a pellet
- ghost_collision_penalty
Penalty for collision with ghost
- step_penalty
Cost per action
- win_reward
Reward for collecting all pellets
- ghost_aggressiveness
Temperature parameter for ghost movement policy
- observation_noise_factor
Multiplier for observation noise based on distance
- max_observation_noise
Maximum noise standard deviation
- dangerous_areas
List of (row, col) centers of circular hazard zones
- dangerous_area_radius
Radius (in grid cells) defining each hazard zone
- dangerous_area_penalty
Penalty subtracted when PacMan ends a step inside a zone
Example
>>> import numpy as np >>> np.random.seed(42) # For reproducible results >>> >>> # Initialize environment >>> env = PacManPOMDP(maze_size=(7, 7)) >>> >>> # Get initial state and actions >>> initial_state = env.initial_state_dist().sample()[0] >>> actions = env.get_actions() >>> >>> # Sample complete step using convenience method >>> action = actions[0] >>> next_state, observation, reward = env.sample_next_step(initial_state, action) >>> >>> # Check terminal condition >>> env.is_terminal(initial_state) False
Example
Construct an env with a circular hazard zone — PacMan is penalised by
dangerous_area_penaltywhenever its realised next position lies inside the zone, but the zone does not block movement or terminate.>>> import numpy as np >>> np.random.seed(0) >>> env = PacManPOMDP( ... maze_size=(7, 7), ... dangerous_areas={(3, 3)}, ... dangerous_area_radius=1.0, ... dangerous_area_penalty=5.0, ... ) >>> state = env.initial_state_dist().sample()[0] >>> _ = env.sample_next_step(state, env.get_actions()[0]) >>> env.dangerous_area_penalty 5.0
- get_metric_names()[source]
Get names of PacMan POMDP specific metrics.
- Return type:
- Returns:
List containing metric names including standard metrics (win_rate, avg_pellets_collected, avg_episode_length, avg_pacman_closest_ghost_distance, avg_collision_encounters, avg_dangerous_area_steps, avg_all_dangerous_encounters) and dynamically generated per-ghost distance metrics for multi-ghost scenarios (avg_pacman_ghost_0_distance, avg_pacman_ghost_1_distance, etc.).
avg_all_dangerous_encountersis the per-step sum of ghost-collision and dangerous-area-step events; a step that is both counts twice.
- get_transition_cpp_ctor_kwargs()[source]
Return the cached per-env kwargs dict passed to PacManTransitionCpp.
- hash_action(action)[source]
Return a hashable key consistent with action equality.
Used by tree-search planners to index action children of a belief node in O(1). The returned key MUST satisfy:
action_a == action_b (per env's notion of equality) ==> hash_action(action_a) == hash_action(action_b)
Subclasses with non-hashable actions (e.g.
np.ndarray) must override to return a hashable surrogate (tobytes()is the standard choice for ndarray actions, which mirrors thenp.array_equalsemantics used by the linear-scan fallback).
- property initial_ghost_pos: Tuple[int, int]
returns first ghost position.
- Type:
Backward compatibility
- initial_observation_dist()[source]
Get the initial observation distribution.
Returns a live distribution that draws fresh noisy ghost-position observations from the true initial state on each
samplecall, instead of the previous Dirac wrapper around a single pre-drawn sample (which collapsed the entire initial-belief observation prior to a point mass).- Return type:
- make_state(*, pacman_pos, ghost_positions, pellets=None, score=0.0, terminal=False)[source]
Build a PacMan state array in the canonical layout.
The array layout is
[pac_row, pac_col, g0_row, g0_col, ..., pellet_mask[0..P-1], score, terminal].- Parameters:
pacman_pos (
Tuple[int,int]) – PacMan grid position(row, col).ghost_positions (
Tuple[Tuple[int,int],...]) – Per-ghost positions as a tuple of lengthnum_ghosts.pellets (
Optional[Tuple[Tuple[int,int],...]]) – Active pellet positions.Nonemeans every initial pellet is active (useful for constructing initial states).score (
float) – Current game score.terminal (
bool) – Whether the state is terminal.
- Return type:
- Returns:
1-D
float64array of shape(self._state_dim,).- Raises:
ValueError – If any argument has the wrong type or length, or if a pellet position was not registered at env construction.
- observation_log_probability(next_state, action, observations)[source]
Log-probability of each candidate observation under
(next_state, action).Returns
np.ndarrayof shape(N,)where N is the number of candidate observations. Subclasses must implement.
- observation_log_probability_per_state(next_states, action, observation)[source]
Log-probability of one observation under each candidate next-state.
Used by particle filters: given N candidate next-states and ONE observation, return N log-likelihoods.
The default implementation falls back to a per-state Python loop delegating to
observation_log_probability(). Native-backed envs (those whose observation kernel exposesbatch_log_likelihood(next_states_array, observation_array)) should override to avoid the loop.
- reward(state, action, next_state=None)[source]
Calculate immediate reward.
Uses the realised
next_statewhen supplied (e.g. byEnvironment.sample_next_step()) so the collision penalty and win bonus reflect the same stochastic ghost transition as the trajectory rather than a fresh independent draw. Whennext_stateisNone, falls back to sampling one here.
- reward_batch(states, action, next_states=None)[source]
Calculate rewards for a batch of states.
Accepts a 2-D numpy array of shape
(N, state_dim)on the fast vectorized path, or a sequence of 1-D state arrays on the fallback per-particle path.Without
next_states, computes deterministic reward components only (step penalty, pellet collection, win bonus); ghost collision penalty is excluded because it depends on the stochastic ghost transition. Whennext_statesis supplied (e.g. by a caller that already realised the batch transition), the collision penalty is included against those realised draws so the per- particle batch reward agrees with the trajectory-driven single-state path.
- sample_next_state(state, action, n_samples=1)[source]
Sample one or more next states for
(state, action).Hot-path entry point used by MCTS planners and particle filters. Subclasses must implement.
- sample_next_state_batch(states, action)[source]
Sample one next state per input state, all under the same action.
Used by particle filters: given N current particles and one action, draw N next states (one per particle) in a single vectorized call.
The default implementation falls back to a per-state Python loop delegating to
sample_next_state(). Native-backed envs (those whose state-transition kernel exposesbatch_sample(states_array)) should override to avoid the loop.
- sample_observation(next_state, action, n_samples=1)[source]
Sample one or more observations for
(next_state, action).Hot-path entry point used by MCTS planners and particle filters. Subclasses must implement.
- simulate_random_rollout(state, action_sampler, max_depth, discount_factor, depth=0)[source]
Estimate the value of
statevia a native C++ random rollout.Pre-draws all action indices in NumPy, then delegates the entire trajectory (transition + reward accumulation) to the C++ kernel. This avoids per-step Python frame overhead for the common path.
- Parameters:
state (
Any) – Current state ndarray.action_sampler (
Any) – Object with asample()method returning a random action; only used to pre-draw action integers.max_depth (
int) – Maximum rollout depth.discount_factor (
float) – Per-step discount factor.depth (
int) – Current depth consumed by the search tree. Defaults to 0.
- Return type:
- Returns:
Discounted cumulative reward along the sampled trajectory.
- transition_log_probability(state, action, next_states)[source]
Log-probability of each candidate next state under
(state, action).Returns
np.ndarrayof shape(N,)where N is the number of candidate next states. Subclasses must implement.
- class POMDPPlanners.environments.pacman_pomdp.PacManVectorizedUpdater(maze_size, num_ghosts, num_pellets, state_dim, ghost_aggressiveness, ghost_coordination, ghost_strategies, observation_noise_factor, max_observation_noise, transition_ctor_kwargs, observation_ctor_kwargs, patrol_dir_state)[source]
Bases:
VectorizedParticleBeliefUpdaterVectorized particle belief updater for PacMan POMDP, native-backed.
Performs all-particle transitions and observation log-likelihoods by dispatching to the
PacManTransitionCppandPacManObservationCppnative kernels.- Parameters:
num_ghosts (int)
num_pellets (int)
state_dim (int)
ghost_aggressiveness (float)
ghost_coordination (str)
ghost_strategies (List[str])
observation_noise_factor (float)
max_observation_noise (float)
transition_ctor_kwargs (Dict[str, Any])
observation_ctor_kwargs (Dict[str, Any])
patrol_dir_state (np.ndarray)
- maze_size
Grid dimensions (rows, cols).
- num_ghosts
Number of ghosts.
- num_pellets
Number of initial pellets.
- state_dim
Dimensionality of the array state.
- ghost_aggressiveness
Softmax temperature for ghost pursuit.
- ghost_coordination
Ghost coordination mode.
- ghost_strategies
Per-ghost strategy list.
- observation_noise_factor
Multiplier for observation noise.
- max_observation_noise
Maximum observation noise std.
- batch_observation_log_likelihood(next_particles, action, observation)[source]
Compute observation log-likelihoods for all particles at once.
- batch_transition(particles, action)[source]
Transition all particles in a single batched operation.
- classmethod from_environment(env)[source]
Construct an updater from a PacManPOMDP instance.
- Return type:
- Parameters:
env (PacManPOMDP)
- POMDPPlanners.environments.pacman_pomdp.create_pacman_belief(env, belief_type=BeliefType.VECTORIZED_PARTICLE, n_particles=200, **kwargs)[source]
Create a ready-to-use belief for the PacMan POMDP.
- Parameters:
env (
PacManPOMDP) – PacManPOMDP environment instance.belief_type (
BeliefType) – Desired belief representation. Defaults toBeliefType.VECTORIZED_PARTICLE.n_particles (
int) – Number of particles. Defaults to 200.**kwargs (
Any) – Extra arguments (reserved for future use).
- Return type:
- Returns:
A configured
Beliefobject.- Raises:
ValueError – If belief_type is not supported.
Example
>>> import numpy as np >>> np.random.seed(42) >>> from POMDPPlanners.environments.pacman_pomdp import PacManPOMDP >>> env = PacManPOMDP(discount_factor=0.95) >>> belief = create_pacman_belief(env, n_particles=50) >>> belief.sample().shape[0] > 0 True
- POMDPPlanners.environments.pacman_pomdp.create_simple_maze_pacman(maze_size=7, num_walls=5, num_ghosts=1, seed=None)[source]
Create a simple PacMan instance with random walls and multiple ghosts.
- Parameters:
- Return type:
- Returns:
Randomly configured PacMan POMDP with multi-ghost support
Subpackages
- POMDPPlanners.environments.pacman_pomdp.pacman_pomdp_beliefs package
PacManVectorizedUpdaterPacManVectorizedUpdater.maze_sizePacManVectorizedUpdater.num_ghostsPacManVectorizedUpdater.num_pelletsPacManVectorizedUpdater.state_dimPacManVectorizedUpdater.ghost_aggressivenessPacManVectorizedUpdater.ghost_coordinationPacManVectorizedUpdater.ghost_strategiesPacManVectorizedUpdater.observation_noise_factorPacManVectorizedUpdater.max_observation_noisePacManVectorizedUpdater.batch_observation_log_likelihood()PacManVectorizedUpdater.batch_transition()PacManVectorizedUpdater.config_idPacManVectorizedUpdater.from_environment()
create_pacman_belief()- Submodules
- POMDPPlanners.environments.pacman_pomdp.pacman_pomdp_beliefs.pacman_belief_factory module
- POMDPPlanners.environments.pacman_pomdp.pacman_pomdp_beliefs.pacman_grid_utils module
- POMDPPlanners.environments.pacman_pomdp.pacman_pomdp_beliefs.pacman_vectorized_updater module
PacManVectorizedUpdaterPacManVectorizedUpdater.maze_sizePacManVectorizedUpdater.num_ghostsPacManVectorizedUpdater.num_pelletsPacManVectorizedUpdater.state_dimPacManVectorizedUpdater.ghost_aggressivenessPacManVectorizedUpdater.ghost_coordinationPacManVectorizedUpdater.ghost_strategiesPacManVectorizedUpdater.observation_noise_factorPacManVectorizedUpdater.max_observation_noisePacManVectorizedUpdater.batch_observation_log_likelihood()PacManVectorizedUpdater.batch_transition()PacManVectorizedUpdater.config_idPacManVectorizedUpdater.from_environment()
- POMDPPlanners.environments.pacman_pomdp.pacman_pomdp_utils package
- Submodules
- POMDPPlanners.environments.pacman_pomdp.pacman_pomdp_utils.numba_kernels module
- POMDPPlanners.environments.pacman_pomdp.pacman_pomdp_utils.pacman_reward_models module
Submodules
POMDPPlanners.environments.pacman_pomdp.pacman_pomdp module
Module for PacMan POMDP environment.
This module provides the PacMan POMDP environment implementation inspired by the classic arcade game. The environment features a grid world where PacMan must collect pellets while avoiding ghosts, with partial observability of ghost positions.
The environment involves PacMan navigating a maze with walls, collecting pellets,
and avoiding ghosts that move according to stochastic policies. PacMan receives
noisy observations about nearby ghost positions. The state is a flat float64
ndarray in the canonical layout
[pac_row, pac_col, g0_row, g0_col, ..., pellet_mask[0..P-1], score, terminal];
build states via PacManPOMDP.make_state() and read fields back with
get_pacman_pos / get_ghost_positions / get_pellets / get_score /
get_terminal.
- Classes:
PacManPOMDP: The main POMDP environment implementation
- class POMDPPlanners.environments.pacman_pomdp.pacman_pomdp.PacManPOMDP(maze_size=(7, 7), walls=None, initial_pellets=None, initial_pacman_pos=(0, 0), num_ghosts=1, initial_ghost_positions=None, initial_ghost_pos=None, pellet_reward=10.0, ghost_collision_penalty=-100.0, step_penalty=-1.0, win_reward=100.0, ghost_aggressiveness=2.0, ghost_coordination='independent', ghost_strategies=None, observation_noise_factor=0.3, max_observation_noise=1.5, dangerous_areas=None, dangerous_area_radius=1.0, dangerous_area_penalty=5.0, discount_factor=0.95, name='PacManPOMDP', output_dir=None, debug=False, reward_model_type=RewardModelType.CONSTANT_HAZARD_PENALTY, penalty_decay=1.0)[source]
Bases:
DiscreteActionsEnvironmentPacMan POMDP environment inspired by the classic arcade game.
This environment implements a simplified PacMan game where PacMan must collect pellets while avoiding a single ghost. The ghost position is only partially observable through noisy sensor readings.
- Parameters:
num_ghosts (int)
pellet_reward (float)
ghost_collision_penalty (float)
step_penalty (float)
win_reward (float)
ghost_aggressiveness (float)
ghost_coordination (str)
observation_noise_factor (float)
max_observation_noise (float)
dangerous_area_radius (float)
dangerous_area_penalty (float)
discount_factor (float)
name (str)
output_dir (Path | None)
debug (bool)
reward_model_type (RewardModelType)
penalty_decay (float)
- maze_size
Grid dimensions as (rows, cols)
- walls
Set of wall positions as (row, col) tuples
- initial_pellets
List of initial pellet positions
- pellet_reward
Reward for collecting a pellet
- ghost_collision_penalty
Penalty for collision with ghost
- step_penalty
Cost per action
- win_reward
Reward for collecting all pellets
- ghost_aggressiveness
Temperature parameter for ghost movement policy
- observation_noise_factor
Multiplier for observation noise based on distance
- max_observation_noise
Maximum noise standard deviation
- dangerous_areas
List of (row, col) centers of circular hazard zones
- dangerous_area_radius
Radius (in grid cells) defining each hazard zone
- dangerous_area_penalty
Penalty subtracted when PacMan ends a step inside a zone
Example
>>> import numpy as np >>> np.random.seed(42) # For reproducible results >>> >>> # Initialize environment >>> env = PacManPOMDP(maze_size=(7, 7)) >>> >>> # Get initial state and actions >>> initial_state = env.initial_state_dist().sample()[0] >>> actions = env.get_actions() >>> >>> # Sample complete step using convenience method >>> action = actions[0] >>> next_state, observation, reward = env.sample_next_step(initial_state, action) >>> >>> # Check terminal condition >>> env.is_terminal(initial_state) False
Example
Construct an env with a circular hazard zone — PacMan is penalised by
dangerous_area_penaltywhenever its realised next position lies inside the zone, but the zone does not block movement or terminate.>>> import numpy as np >>> np.random.seed(0) >>> env = PacManPOMDP( ... maze_size=(7, 7), ... dangerous_areas={(3, 3)}, ... dangerous_area_radius=1.0, ... dangerous_area_penalty=5.0, ... ) >>> state = env.initial_state_dist().sample()[0] >>> _ = env.sample_next_step(state, env.get_actions()[0]) >>> env.dangerous_area_penalty 5.0
- get_metric_names()[source]
Get names of PacMan POMDP specific metrics.
- Return type:
- Returns:
List containing metric names including standard metrics (win_rate, avg_pellets_collected, avg_episode_length, avg_pacman_closest_ghost_distance, avg_collision_encounters, avg_dangerous_area_steps, avg_all_dangerous_encounters) and dynamically generated per-ghost distance metrics for multi-ghost scenarios (avg_pacman_ghost_0_distance, avg_pacman_ghost_1_distance, etc.).
avg_all_dangerous_encountersis the per-step sum of ghost-collision and dangerous-area-step events; a step that is both counts twice.
- get_transition_cpp_ctor_kwargs()[source]
Return the cached per-env kwargs dict passed to PacManTransitionCpp.
- hash_action(action)[source]
Return a hashable key consistent with action equality.
Used by tree-search planners to index action children of a belief node in O(1). The returned key MUST satisfy:
action_a == action_b (per env's notion of equality) ==> hash_action(action_a) == hash_action(action_b)
Subclasses with non-hashable actions (e.g.
np.ndarray) must override to return a hashable surrogate (tobytes()is the standard choice for ndarray actions, which mirrors thenp.array_equalsemantics used by the linear-scan fallback).
- property initial_ghost_pos: Tuple[int, int]
returns first ghost position.
- Type:
Backward compatibility
- initial_observation_dist()[source]
Get the initial observation distribution.
Returns a live distribution that draws fresh noisy ghost-position observations from the true initial state on each
samplecall, instead of the previous Dirac wrapper around a single pre-drawn sample (which collapsed the entire initial-belief observation prior to a point mass).- Return type:
- make_state(*, pacman_pos, ghost_positions, pellets=None, score=0.0, terminal=False)[source]
Build a PacMan state array in the canonical layout.
The array layout is
[pac_row, pac_col, g0_row, g0_col, ..., pellet_mask[0..P-1], score, terminal].- Parameters:
pacman_pos (
Tuple[int,int]) – PacMan grid position(row, col).ghost_positions (
Tuple[Tuple[int,int],...]) – Per-ghost positions as a tuple of lengthnum_ghosts.pellets (
Optional[Tuple[Tuple[int,int],...]]) – Active pellet positions.Nonemeans every initial pellet is active (useful for constructing initial states).score (
float) – Current game score.terminal (
bool) – Whether the state is terminal.
- Return type:
- Returns:
1-D
float64array of shape(self._state_dim,).- Raises:
ValueError – If any argument has the wrong type or length, or if a pellet position was not registered at env construction.
- observation_log_probability(next_state, action, observations)[source]
Log-probability of each candidate observation under
(next_state, action).Returns
np.ndarrayof shape(N,)where N is the number of candidate observations. Subclasses must implement.
- observation_log_probability_per_state(next_states, action, observation)[source]
Log-probability of one observation under each candidate next-state.
Used by particle filters: given N candidate next-states and ONE observation, return N log-likelihoods.
The default implementation falls back to a per-state Python loop delegating to
observation_log_probability(). Native-backed envs (those whose observation kernel exposesbatch_log_likelihood(next_states_array, observation_array)) should override to avoid the loop.
- reward(state, action, next_state=None)[source]
Calculate immediate reward.
Uses the realised
next_statewhen supplied (e.g. byEnvironment.sample_next_step()) so the collision penalty and win bonus reflect the same stochastic ghost transition as the trajectory rather than a fresh independent draw. Whennext_stateisNone, falls back to sampling one here.
- reward_batch(states, action, next_states=None)[source]
Calculate rewards for a batch of states.
Accepts a 2-D numpy array of shape
(N, state_dim)on the fast vectorized path, or a sequence of 1-D state arrays on the fallback per-particle path.Without
next_states, computes deterministic reward components only (step penalty, pellet collection, win bonus); ghost collision penalty is excluded because it depends on the stochastic ghost transition. Whennext_statesis supplied (e.g. by a caller that already realised the batch transition), the collision penalty is included against those realised draws so the per- particle batch reward agrees with the trajectory-driven single-state path.
- sample_next_state(state, action, n_samples=1)[source]
Sample one or more next states for
(state, action).Hot-path entry point used by MCTS planners and particle filters. Subclasses must implement.
- sample_next_state_batch(states, action)[source]
Sample one next state per input state, all under the same action.
Used by particle filters: given N current particles and one action, draw N next states (one per particle) in a single vectorized call.
The default implementation falls back to a per-state Python loop delegating to
sample_next_state(). Native-backed envs (those whose state-transition kernel exposesbatch_sample(states_array)) should override to avoid the loop.
- sample_observation(next_state, action, n_samples=1)[source]
Sample one or more observations for
(next_state, action).Hot-path entry point used by MCTS planners and particle filters. Subclasses must implement.
- simulate_random_rollout(state, action_sampler, max_depth, discount_factor, depth=0)[source]
Estimate the value of
statevia a native C++ random rollout.Pre-draws all action indices in NumPy, then delegates the entire trajectory (transition + reward accumulation) to the C++ kernel. This avoids per-step Python frame overhead for the common path.
- Parameters:
state (
Any) – Current state ndarray.action_sampler (
Any) – Object with asample()method returning a random action; only used to pre-draw action integers.max_depth (
int) – Maximum rollout depth.discount_factor (
float) – Per-step discount factor.depth (
int) – Current depth consumed by the search tree. Defaults to 0.
- Return type:
- Returns:
Discounted cumulative reward along the sampled trajectory.
- transition_log_probability(state, action, next_states)[source]
Log-probability of each candidate next state under
(state, action).Returns
np.ndarrayof shape(N,)where N is the number of candidate next states. Subclasses must implement.
- class POMDPPlanners.environments.pacman_pomdp.pacman_pomdp.PacManPOMDPMetrics(*values)[source]
Bases:
EnumMetric names for PacMan POMDP environment.
- AVG_ALL_DANGEROUS_ENCOUNTERS = 'avg_all_dangerous_encounters'
- AVG_COLLISION_ENCOUNTERS = 'avg_collision_encounters'
- AVG_DANGEROUS_AREA_STEPS = 'avg_dangerous_area_steps'
- AVG_EPISODE_LENGTH = 'avg_episode_length'
- AVG_PACMAN_CLOSEST_GHOST_DISTANCE = 'avg_pacman_closest_ghost_distance'
- AVG_PELLETS_COLLECTED = 'avg_pellets_collected'
- WIN_RATE = 'win_rate'
- class POMDPPlanners.environments.pacman_pomdp.pacman_pomdp.RewardModelType(*values)[source]
Bases:
EnumReward-model variants selectable on
PacManPOMDP.- CONSTANT_HAZARD_PENALTY = 'constant_hazard_penalty'
- DISTANCE_DECAYED_HAZARD_PENALTY = 'distance_decayed_hazard_penalty'
- ZERO_MEAN_HAZARD_SHOCK = 'zero_mean_hazard_shock'
- POMDPPlanners.environments.pacman_pomdp.pacman_pomdp.create_simple_maze_pacman(maze_size=7, num_walls=5, num_ghosts=1, seed=None)[source]
Create a simple PacMan instance with random walls and multiple ghosts.
- Parameters:
- Return type:
- Returns:
Randomly configured PacMan POMDP with multi-ghost support
POMDPPlanners.environments.pacman_pomdp.pacman_visualizer module
Visualization module for PacMan POMDP environment.
This module provides sprite-based visualization capabilities for PacMan POMDP episodes, rendering animated GIFs of agent behavior and game state.
- Classes:
PacManVisualizer: Handles sprite-based rendering and GIF generation
- class POMDPPlanners.environments.pacman_pomdp.pacman_visualizer.PacManVisualizer(environment, tile_size=32)[source]
Bases:
objectHandles visualization for PacMan POMDP environments.
This class manages sprite loading, frame rendering, and GIF generation for visualizing PacMan POMDP episodes. It renders the maze, PacMan, ghosts, pellets, and game state information.
- Parameters:
environment (PacManPOMDP)
tile_size (int)
- env
Reference to the PacMan POMDP environment
- tile_size
Size of each tile in pixels
- sprites
Dictionary of loaded sprite images
- visualize_path(path, actions, cache_path, beliefs=None)[source]
Visualize PacMan path through the maze using sprite-based rendering.
- Parameters:
path (
List[ndarray]) – List of state arrays representing the path through the maze.cache_path (
Path) – Path where the GIF should be saved.beliefs (
Optional[List[Optional[Belief]]]) – Optional per-frame beliefs. When supplied, each frame overlays a translucent red heatmap over the cells the belief assigns non-zero ghost-occupation probability.
- Raises:
TypeError – If cache_path is not a Path object.
- Return type: