Tarea: escriba una función que se llame en cada iteración del juego y le diga a la entidad a dónde ir a continuación. (Se espera que la salida sea "derecha", "izquierda", "arriba", "abajo").
* @typedef {Object} Point - coordinates on the map * @property {number} x * @property {number} y * * @typedef {Object} Pickup - A "food" object that can be picked up or "eaten" * @property {'pacdot' | type 'powerPellet'} - type of food * @property {Point} position - the position of the object on the map * @property {boolean} take - flag whether the object was raised or "eaten" * * @typedef {Object} Pacman - Pacman object * type @property {'pacman'} - type pacman * @property {Point} position - pacman position on the map * * @typedef {Pickup | Pacman | Ghost} Entity - one of the game entities * * @param {Entity []} entity - Array of entities on the game map * @param {string [] []} maze - The initial state of the game maze, where each value is: * - 'X' - labyrinth wall * - 'o' - food or "points" for which points are awarded * - '' - free space in the maze * @return {'up' | 'down' | "left" | 'right'} the direction the pakman needs to go * /La idea de implementar la función es simple: escriba las coordenadas actuales del pakman, marque: a la derecha - comida ("o") o a la derecha - vacío (" "), si es así, muévase a la derecha. NOTA : es suficiente escribir una función que funcione para el nivel que se muestra en la foto. Es decir, siempre volveremos "a la derecha". Lo importante es cómo se calcula. A continuación se muestra un fragmento de código que no funciona para mí. Les pido que den pistas sobre por qué las pruebas pueden no pasar (estoy trabajando con esas cosas por primera vez, no se apresuren). Hacer clic
let PacmanX = entities[Pacman].Point.x; let PacmanY = entities[Pacman].Point.y; let checkRightCell = maze[PacmanX+1][PacmanY]; if (checkRightCell === 'o' || checkRightCell === ' ') return 'right'; // output-error: Pacman is not defined