boardgame.io icon indicating copy to clipboard operation
boardgame.io copied to clipboard

Log rewind broken (for multiplayer games)

Open nicolodavis opened this issue 6 years ago • 3 comments

The log rewind works as follows:

  • We restore to the initial state of the game.
  • We apply all the moves after that up to the rewind point.

The client essentially applies all the Redux actions over the store in order. This works fine in single player games, but for multiplayer games there are a couple of problems:

  • secret state is not available on the client (so it can't replay the game accurately).
  • the client reducers bail out early due to the above, so some actions are not even applied.

For rewind to work more predictably, we probably need to store the entire state after each update (in a separate area of storage).

nicolodavis avatar Mar 24 '18 10:03 nicolodavis

Hi, I met a strange problem. When I call props.undo, I find that the state remains not changed. Then I use the redux dev tools to debug, I found the _undo list never changes (only an initial state which you add in flow.js startTurn). Do I misunderstand the usage of undo? Or there are something I forget?

gitter message copied to here. Maybe my problem is related to this issue?

titanxxh avatar May 10 '18 12:05 titanxxh

I think the log rewind can only work predictably when it is done on the server. Storing the entire state means storing the secrets also, which is exactly what is not supposed to happen client-side. Am I missing something?

D'oh, of course, the entire state is the state with all actions applied, so secrets are not revealed in any way. And this will increase the size of the serialized games massively, so put it in a a separate storage area to add flexibility.

Stefan-Hanke avatar Oct 10 '18 05:10 Stefan-Hanke

Yes, at the moment it is feasible to store:

  1. The initial game state.
  2. The actions taken so far.
  3. The latest state (redundant, but still good to have).

After this change, we'll have to store one game state for every action taken. I'm not so worried about the exact size that is stored (storage is cheap). But yes, we can put it in a separate area (each DB adapter can decide if it wants to implement this storage level optimization).

nicolodavis avatar Oct 10 '18 13:10 nicolodavis