In the 2048 game each move causes a new 2-block to spawn. However, I couldn't figure out the logic behind where that block spawns. Is it random? Does it depend on the direction of your last move?


It's randomly chosen out of the available cells, as seen in the code here:

if (cells.length) 
    return cells[Math.floor(Math.random() * cells.length)];

(which is used here and eventually here)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.