Skip to content

setFood() #3

Description

Max,

i refactored this function and as per console.time() it is a lot faster.
The original version is executed in 0.300-500ms, this one in 0.010-0.020.
I found that interesting.

function setFood() {
var randomX= Math.round(Math.random() * (grid.width - 1)),
randomY= Math.round(Math.random() * (grid.height - 1));

  if(grid.get(randomX, randomY) === SNAKE) {
    setFood();
  } else {
    grid.set(FRUIT, randomX, randomY);
  }      

}

Thanks for the great tutorials.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions