question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dump / restore game state to / from json.

See original GitHub issue

This is a feature request

It would be nice to see a simple api to dump game state to json and restore it. Something like

let json = game.dump()
game.restore(json)

This could be used to save games in a database or create save/restore points.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
brozephcommented, Apr 18, 2018

@Piterden - thank you for sharing! It looks like you’re saving each move into a table and then restoring the board by re-applying each move individually. This is effectively what I did in the stdlib implementation.

An alternative, I recently noticed, which I forgot about in my original reply on this issue thread, that there is a way to load a game from a move history: https://github.com/brozeph/node-chess/blob/master/src/game.js#L86. One possibility might be to serialize the move history as JSON (JSON.stringify(gameClient.game.moveHistory)) and then use that when creating a game subsequently for reload… if this sounds interesting or worthwhile, I could implement a load method from the game clients that does just this (as an alternative to the create method).

0reactions
brozephcommented, Mar 1, 2021

Should we keep this issue open, or does the FEN load address this need?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support saving game state · Issue #18 · bfirsh/jsnes-web · GitHub
Dump snapshot of whole emulator to JSON and restore. See bfirsh/jsnes#16 for existing issue and bfirsh/jsnes#42 for existing implementation.
Read more >
How can I save the state of my bot's activity with json?
import json, pickle with open('BOT_STATE_NAME.pkl', 'w') as fp: json.dump(sample, fp). Then, when your bot will be changing it`s state, ...
Read more >
Save and load Python data with JSON - Opensource.com
Meanwhile, the JSON module's dump function is used to dump the data from the dict into the data file. Saving data from your...
Read more >
JSON – Logic_bot - Oregon State University
Finally we can use json.dump() to send the formatted string to the file that ... saved pretend we are starting a new instance...
Read more >
Python Tutorial: json.dump(s) & json.load(s) - 2021
json.load(s) & json.dump(s). python-json-load-loads-dump-dumps.png. There are two ways of reading in (load/loads) the following json file, in.json:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found