Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

271
Visualizações
Function for moving an object (working with the game engine)

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
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda