I think it works. My town.zzt scrambler has swapped two random boards 10,000 times to create shuffle.zzt
which has shuffled boards that look to be linked correctly. I would like someone to play this game through from beginning to end, and make sure that it works. DON'T CHEAT! The point is to make sure that all the gameplay is preserved. I mean, ammo and heath cheating is okay, but play everything through in the correct order and visit all the boards. The goal is to make sure that libzzt2 has preserved the boards' content while changing their position in the file. And hey, it might be fun to play town over again :)
More technical details, for those really interested, but mostly for me to come back to later:
The heart of zztWorldMoveBoard() is determining what boards link to the board that is being moved, and then to change those links after the board is moved. Everything else is pretty much taken care of by zztWorldInsertBoard(), zztWorldDeleteBoard(), etc.
The function first goes through each board and checks for a link to the board-to-be-moved. Then it makes a record of what board to set this link to after the move has been made. The (flawed) statement I used was this:
board = (i > src && i < dest) ? i-1 : i;
is the number of the board that will get set to the new position of the board-to-be-moved after it is moved. This worked for moving boards to higher places, but not lower.
Last night, I realized that I should be checking if it's
(i > (lower number) && i < (higher number))
. This didn't work either, because it was still setting it to i-1.
Finally, with the code that sets high and low to the higher/lower board between src and dest, I added a line to have it subtract 1 if it's moving up the list, or add one if it's moving down the list. This got called
for some reason.
The final result looks like this:
board = (i >= low && i <= high) ? i+coefficient : i;