rust-sokoban
rust-sokoban copied to clipboard
Box can move in situation where it shouldn't move
Steps to reproduce:
- Get local copy of directory listed at https://github.com/iolivia/rust-sokoban/tree/master/code/rust-sokoban-c02-03
- Change contents of const MAP in main.rs to
N N W W W W W W
W W W . . . . W
W . P W B . . W
W . . . . . . W
W . . . . . . W
W . . . . . . W
W . . S . . . W
W . . . . . . W
W W W W W W W W
- Build and run the game
- Press the right arrow key
- Observe: https://cdn.discordapp.com/attachments/739458870853894215/739459125720776704/sokoban-bug.mp4
I was able to stop the behaviour by changing the match expression on line 173 to
match immov.get(&pos) {
Some(id) => {
to_move.clear();
break
},
None => break,
}
I haven't tested rigorously to see whether or not this introduces any new unwanted behaviour, but it seems to not do so.
Since the attached video seems corrupt, here's the result:

where the box is moved even though it is obstructed by a wall.
This fix also prevents multiple of the same sounds playing at the same time when audio is introduced. When this happens it appears that the sounds suddenly got louder, but that's just what happens when the same sound is played simultaneously.