Skip to content
Advertisement

How would I move a blank space in a 2d array?

I’m working on a Slider puzzle game and I’m not sure how I would go about moving a “blank” around the array. The puzzle would something like this but randomized. Each method has a prerequisite indicating if it can move a certain direction or not.

JavaScript
JavaScript

Advertisement

Answer

Here is an example of how you could implement right(), the rest of the methods would follow very similarly. I am assuming, as your comments imply, that the legality of the move has already been verified.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement