3 ms·
I do this all the time when I write a game which can easily be described as a sequence of discrete moves. Chess is a good example, and games with physics engine
by default-kramer 9y ago
I do this all the time when I write a game which can easily be described as a sequence of discrete moves. Chess is a good example, and games with physics engines are the opposite. As you said, the Undo operation is just "start with the initial board and apply N-1 moves to get the current state." This plays nicely with immutability too.
- terminalcommand 9y agoStarting with the initial board and applying n-1 moves should be significantly slower than using immutable data structures. I don't have much experience in algorithms but I think O(1) trumps O(N-1) :).
- wila 9y agoThe problem with graphics though is that some graphical operations are destructive so you can't just undo the operation. In order to undo without a redo list, you would have to keep a complete graphical representation of the image and each operation. With images the memory usage goes up very quickly in that case, copying large blocks of memory on each operation makes your image editing slow down too.