0 votes

I'm trying to make a simple sokoban puzzle game with an undo feature. I've made an array of previous scene states (duplicates of the scene node at different points in time) that can be loaded back to by pressing the undo button, so if you push a crate too far for example, you can undo a few times to before you pushed it.

My problem is that doing a move that doesnt do anything, like trying to push against a wall, saves a state thats the exact same as the previous one, requiring you to undo twice. Is there anyway for me to check if two of these scene node duplicates have the same properties so I can remove repeats?

Godot version 3.5.1
in Engine by (15 points)

1 Answer

+1 vote

I think a better way would be to check if any object moved before saving the scene for your
undo purpose. That would require you to save the positions of all blocks and the player to an array then have another array holding current positions of the blocks and player. Compare these arrays in the process function using == and if they don't match, save that for undo. This shouldn't be hard to implement or affect performance since sokoban has just a few movable blocks.

by (2,003 points)

IIRC, in Sokoban, the player has to move in a given turn for anything to "have happened" in the game.

With that in mind, as a further optimization to the above suggestion, can't you just check if the player has moved after each turn? If the player moved, you'd want to save an undo state. If the player did not move, don't save the state.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.