I'm implementing a simple "turn based" game where the player sets up a bunch of "actions" on a board and "objects" move on the board and are influences by those actions. The player is no longer involved after setting up the board and just watches the actions play out. Each "turn" of the game loop, a "move right" action will move any objects on its square one square to the right, for example.
My problem is now that each time I run the game loop, all actions are executed as follows:
for(auto& go: gameObjects) {
go->update();
}
Each of these game objects mutates the world state in its update() method. What I'm seeing now is that when the board is updated by one object, the next one will immediately use that updated board state and perform its action "too soon".
For example: When I place three "move right" actions on the board and run the game loop, the object will be moved three spaces in one "turn" while it should actually take 3 "turns" for the object to move through all 3 of those actions.
How can I delay the board state update until all actions have had their chance to decide what to do? I'm considering two strategies:
Copy the board state for each turn and create a new board state as the result of a turn. This is complicated because all my views are tied to the objects on the board. If I copy the board, I'll have to re-create all views?
Have each action not update the world state, but only return a function which, when executed, will do the update. Once I have all the functions collected, execute them all to update the board.
Any suggestions?