I am working on implementing a search algorithm for the Ms Pacman AI. I thought it would be a good idea to start off with some basic searches like BFS or DFS. I just implemented a BFS but when i ran my code, ms pacman ran into a wall. I was wondering, is there something i could improve with my BFS code or is it just not sufficient enough?
public MOVE BFS(Game game){
EnumMap<Constants.GHOST,MOVE> ghostMove = new EnumMap<>(Constants.GHOST.class);
MOVE bestMove = MOVE.NEUTRAL;
Queue<Game> q = new LinkedList<>();
q.add(game.copy());
while(!q.isEmpty()){
Game current = q.peek();
q.remove();
for (MOVE move : current.getPossibleMoves (current.getPacmanCurrentNodeIndex())) {
Game neighbor = game.copy();
neighbor.advanceGame(move, ghostMove);
q.add(neighbor);
if ((current.getNumberOfActivePills() == 0) && (current.getNumberOfActivePowerPills() == 0)) {
return move;
}
}
}
return bestMove;
}