How to tell if two nodes have the same properties?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By thatfella12

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?

:bust_in_silhouette: Reply From: magicalogic

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.

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.

jgodfrey | 2022-11-18 02:44