Task: write a function that is called at each game iteration and tells the entity where to go next. (output is expected to be "right", "left", "up", "down").
* @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
* /
The idea of implementing the function is simple: write down the current coordinates of the pakman, check: on the right - food ("o") or on the right - empty (" "), if yes - move to the right. NOTE: it is enough to write a function that will work for the level shown in the photo. That is, we will always return "right". The important thing is how it is calculated. Below is a piece of code that does not work for me. I ask you to give hints as to why the tests may not pass (I am working with such things for the first time, do not rush). Click
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