Pacman Torben Petré
Loading...
Searching...
No Matches
logic::GhostNavigator Class Reference

#include <GhostNavigator.h>

Static Public Member Functions

static bool sameDirection (Moves a, Moves b)
 Compares Move a and b and returns whether they are in the same direction.
static bool isAtIntersection (const World &world, const GhostModel &ghost)
 Checks whether the provided Ghost currently is at an intersection.
static std::vector< MovesgetPossibleMoves (const World &world, const GhostModel &ghost)
 Checks all possible directions the Ghost can go at its current position and returns them.
static std::list< MovesfindPathToSpawn (const World &world, const GhostModel &ghost)
 Determines the fastest path back to the Ghost enclosure starting from the Ghost position using BFS pathfinding.
static Moves maximizeDistance (const World &world, const GhostModel &ghost)
 Will return the best Move from all possible moves to maximize the Manhattan distance between the Ghost and Pacman.
static Moves minimizeDistance (const World &world, const GhostModel &ghost, int targetX, int targetY)
 Will return the best Move from all possible moves to minimize the Manhattan distance between the Ghost and the provided target.

Member Function Documentation

◆ findPathToSpawn()

std::list< Moves > GhostNavigator::findPathToSpawn ( const World & world,
const GhostModel & ghost )
staticnodiscard

Determines the fastest path back to the Ghost enclosure starting from the Ghost position using BFS pathfinding.

Parameters
worldWorld
ghostGhost in need of a path
Returns
An ordered list of moves to be strictly followed

A breadth-first search is started from the ghost's current grid position and expands outward until the spawn position is reached. During the search, the direction taken to enter each cell is recorded.

Once the spawn tile is found, the path is reconstructed by walking backwards from the spawn to the start using the recorded directions, producing a sequence of concrete Moves (LEFT, RIGHT, UP, DOWN).

The returned list represents the shortest possible path in grid steps. If multiple shortest paths exist, the chosen one depends on exploration order.

◆ getPossibleMoves()

std::vector< Moves > GhostNavigator::getPossibleMoves ( const World & world,
const GhostModel & ghost )
staticnodiscard

Checks all possible directions the Ghost can go at its current position and returns them.

Parameters
worldWorld
ghostGhost to be checked
Returns
A vector of moves

◆ isAtIntersection()

bool GhostNavigator::isAtIntersection ( const World & world,
const GhostModel & ghost )
staticnodiscard

Checks whether the provided Ghost currently is at an intersection.

Parameters
worldWorld
ghostGhost to be checked
Returns
Whether ghost is at intersection

◆ maximizeDistance()

Moves GhostNavigator::maximizeDistance ( const World & world,
const GhostModel & ghost )
staticnodiscard

Will return the best Move from all possible moves to maximize the Manhattan distance between the Ghost and Pacman.

Parameters
worldWorld
ghostGhosts to be checked
Returns
Best move

◆ minimizeDistance()

Moves GhostNavigator::minimizeDistance ( const World & world,
const GhostModel & ghost,
int targetX,
int targetY )
staticnodiscard

Will return the best Move from all possible moves to minimize the Manhattan distance between the Ghost and the provided target.

Parameters
worldWorld
ghostGhosts to be checked
targetXX grid target coordinate
targetYY grid target coordinate
Returns
Best move

◆ sameDirection()

bool GhostNavigator::sameDirection ( Moves a,
Moves b )
staticnodiscard

Compares Move a and b and returns whether they are in the same direction.

Parameters
aMove
bMove
Returns
Whether they are the same direction

The documentation for this class was generated from the following files: