Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!