[Python] pathfinding with a numpy array

Discussão em 'Python' iniciado por Stack, Fevereiro 4, 2025.

  1. Stack

    Stack Membro Participativo

    I am currently making a pacman game and need to make a function of some sort that can give 4 outputs to decide whether the ghost should go up down left or right in order to chase the player

    [[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
    [0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0]
    [0 2 0 0 0 1 0 0 0 1 1 0 1 0 1 0 0 0 1 0]
    [0 1 0 0 0 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0]
    [0 1 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 1 0]
    [0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0]
    [0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0]
    [1 1 1 1 1 1 0 3 1 1 1 1 1 0 1 1 1 1 1 1]
    [0 0 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 0 0]
    [0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0]
    [0 1 0 0 1 0 1 0 1 0 0 0 0 1 0 1 0 0 1 0]
    [0 1 0 0 1 0 1 0 1 1 1 1 0 1 0 1 0 0 1 0]
    [0 1 0 0 1 0 1 0 0 0 0 1 0 1 0 1 0 0 1 0]
    [0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0]
    [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]


    I currently have this array where 1 is a wall 0 is free space to move into 2 is the players position and 3 is the ghost position and I only need it to determine the first movement it should take as it will re run the function when the player next moves one tile and I was just wondering if anyone was able to provide a possible solution as I am very stuck. also diagonal movement is not allowed. thank you

    Continue reading...

Compartilhe esta Página