DreTheLearner
DreTheLearner

Reputation: 1

Implementing the A* algorithm for Berkeley PacMan

I’m a student and on one of my courses I’m learning AI coding with Python. Right now I’m trying to implement the A* algorithm on Berkeley’s Pacman, but I’m struggling to implement it. I understand how that algorithm works.

I tried to code something "that I'll put next to my explanation" and the goal is to find the path to the nearest food until there's no food left.

def a_star(self, current_state, start_pos, food_pos_list):

    open_list = PriorityQueue()  # Empty Priority Queue
    cost = {}  # Cost

    if not food_pos_list:
        return None

    open_list.push(start_pos, 0)

    while not open_list.is_empty(): 
        current = open_list.pop()
        start_h = min(util.manhattan_distance(start_pos, food) for food in food_pos_list)  # shortest manhattan distance to food

        if current in food_pos_list:
            path = []
        
    return []

That's all I've done for now.

Upvotes: 0

Views: 46

Answers (0)

Related Questions